Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Need help..! (http://www.go4expert.com/forums/need-help-t24326/)

h994422 31Dec2010 00:58

Need help..!
 
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.

h994422 31Dec2010 00:59

Re: Need help..!
 
******************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.


h994422 31Dec2010 01:00

Re: Need help..!
 
**************************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.


h994422 31Dec2010 01:01

Re: Need help..!
 
***************************Using class Time
Code:

#include <iostream>
#include "Time.h"
using namespace std;
int main ()
{
        Time myTime;
        cout << myTime.displayTime() << endl;
        return 0;
}


kevie 31Dec2010 08:12

Re: Need help..!
 
why couldnt you run it?

h994422 31Dec2010 10:26

Re: Need help..!
 
I mean it's not working.The editor (C free 5.0) gave error messages.

jimblumberg 31Dec2010 20:34

Re: Need help..!
 
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

h994422 1Jan2011 02:32

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


All times are GMT +5.5. The time now is 22:07.