Need help..!

h994422's Avatar, Join Date: Sep 2010
Go4Expert 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.
0
h994422's Avatar, Join Date: Sep 2010
Go4Expert 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 shabbir; 31Dec2010 at 07:08.. Reason: Code blocks
0
h994422's Avatar, Join Date: Sep 2010
Go4Expert 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 shabbir; 31Dec2010 at 07:08.. Reason: Code blocks
0
h994422's Avatar, Join Date: Sep 2010
Go4Expert 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 shabbir; 31Dec2010 at 07:09.. Reason: Code blocks
0
kevie's Avatar, Join Date: Dec 2010
Newbie Member
why couldnt you run it?
0
h994422's Avatar, Join Date: Sep 2010
Go4Expert Member
I mean it's not working.The editor (C free 5.0) gave error messages.
0
jimblumberg's Avatar
Ambitious contributor
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
0
h994422's Avatar, Join Date: Sep 2010
Go4Expert Member
We found our mistake. We are beginners right. We have the right to make mistakes
Thanks levie and jim. See you..!