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

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.

h994422 31Dec2010 01:00

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

h994422 31Dec2010 01:01

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

#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).


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 09:06.