1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Need help..!

Discussion in 'C++' started by h994422, Dec 30, 2010.

  1. h994422

    h994422 New Member

    Hi everybody. Happy new year..!
    I am on a course. Data Structures and Algorithms. We are on the second week. Teacher gave us a problem to code. We Wrote sth but we couldn't run it. Could yoou check and tell me our faults. Thanks.

    Q: Design and implement an Abstract Data Type (ADT) that represents the time of day.Represent the time as hours and minutes on a 24 hour clock. The hours and minutes are the private data members of the class that implements the ADT.
    Include at least two initialization operations: one that provides a default value for the time, and another that sets the time to a client-supplied value.These operations are the class's constructors.
    Include operations that set the time, increase the present time by a number of minutes, and display the time in 12 hour and 24 hour notations.
  2. h994422

    h994422 New Member

    ******************header file
    class Time
    	//DEFAULT CONSTRUCTOR:Creates a time and initializes its value to default value.
    	Time(int initialHour, int initialMinute);
    	//CONSTRUCTOR:Creates a time and initializes its value.
    	void setTime(int setHour, int setMinute);
    	//Sets the time.
    	void increaseTime();
    	//Increases the present time by a number of minutes.
    	void displayTime();
    	//Displays the time in 12-hour and 24-hour notations.
    	int theHour,theMinute;			
    };	//end class
    //end of header file.
    Last edited by a moderator: Dec 31, 2010
  3. h994422

    h994422 New Member

    **************************implementation file
    #include <iostream>
    #include "Time.h"		//header file 
    using namespace std;
    }	//end of default constructor
    Time::Time(int initialHour, int initialMinute)
    	cout << "Saati giriniz : ";
    		cin >> initialHour;
    	cout << "Dakikayi giriniz : ";
    		cin >> initialMinute;
    }	//end constructor
    void Time::setTime(int setHour, int setMinute)
    	cout << "Ayarlamak istediginiz saati giriniz : ";
    		cin >> setHour;
    	cout << "Ayarlamak istediginiz dakikayi giriniz : ";
    		cin >> setMinute;
    void Time::increaseTime()
    	int x,increaseMinute;
    	cout << "Kac dakika ileri almak istiyorsunuz (1..60) :";
    		cin >> increaseMinute;
    	while (x>59)
    		cout<< "Dakika 59'dan fazla olmamalidir"
    			<< endl
    			<< "Kac dakika ileri almak istiyorsunuz (1..60) :";
    				cin >> increaseMinute; 
    		theMinute=(theMinute)%60; 	// minute is between 0-60...
    		if (theHour>23) 			//hour is between 0-24
    void Time::displayTime()
      cout <<"\n theHour/theMinute="   << setTime()
           << endl;	//end displayTime.
    // end of implementation file.
    Last edited by a moderator: Dec 31, 2010
  4. h994422

    h994422 New Member

    ***************************Using class Time
    #include <iostream>
    #include "Time.h"
    using namespace std;
    int main ()
    	Time myTime;
    	cout << myTime.displayTime() << endl;
    	return 0;
    Last edited by a moderator: Dec 31, 2010
  5. kevie

    kevie New Member

    why couldnt you run it?
  6. h994422

    h994422 New Member

    I mean it's not working.The editor (C free 5.0) gave error messages.
  7. jimblumberg

    jimblumberg New Member

    Please post the entire warning messages.

    You probably should change the names of your files because if you happen to be using an operating system where file names are not case sensitive Time.h and time.h might be conflicting (time.h is a standard c header file).

  8. h994422

    h994422 New Member

    We found our mistake. We are beginners right. We have the right to make mistakes:)
    Thanks levie and jim. See you..!

Share This Page