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
    Code:
    class Time
    {
    	public:
    	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.
    	private:
    	int theHour,theMinute;			
    };	//end class
    //end of header file.
     
    Last edited by a moderator: Dec 31, 2010
  3. h994422

    h994422 New Member

    **************************implementation file
    Code:
    #include <iostream>
    #include "Time.h"		//header file 
    using namespace std;
    Time::Time():theHour(11),theMinute(11)
    {
    }	//end of default constructor
    Time::Time(int initialHour, int initialMinute)
    {
    	cout << "Saati giriniz : ";
    		cin >> initialHour;
    	cout << "Dakikayi giriniz : ";
    		cin >> initialMinute;
    	theHour=initialHour;
    	theMinute=initialMinute;
    }	//end constructor
    void Time::setTime(int setHour, int setMinute)
    {
    	cout << "Ayarlamak istediginiz saati giriniz : ";
    		cin >> setHour;
    	cout << "Ayarlamak istediginiz dakikayi giriniz : ";
    		cin >> setMinute;
    	theHour=setHour;
    	theMinute=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+=increaseMinute; 
    	if(theMinute>59)
    	{
    		theMinute=(theMinute)%60; 	// minute is between 0-60...
    		theHour+=1;
    		if (theHour>23) 			//hour is between 0-24
    			theHour=(theHour)%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
    Code:
    #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).

    Jim
     
  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