IN C The Time class Design a class named Time The class cont
IN C++
(The Time class) Design a class named Time. The class contains:
(The Time class) Design a class named Time. The class contains:
* * The data fields hour, minute, and second that represent a time. *
A no-arg constructor that creates a Time object for the current time. * (The values of the data fields will represent the current time.) *
A constructor that constructs a Time object with a specified elapsed time since midnight, * January 1, 1970, in milliseconds. (The values of the data fields will represent this time.) *
A constructor that constructs a Time object with the specified hour, minute, and second. *
Three get fuctions for the data fields hour, minute, and second, respectively. *
A function named setTime(int elapseTime) that sets a new time for the object using the * elapsed time. For example, if the elapsed time is 555550000 milliseconds, * the hour is 10, the minute is 19, and the second is 10. * * *
Write a test program that creates two Time objects one using a no arg constructor and the other using Time(555550) and displays their hour, minute, and second in the format hour:minute:second.
And this is what I have so far:
#include
#include
class Time
{
public:
int hour, minute, second, elapseTime;
Time() {
elapseTime = 0;
}
Time() {
int totalSecounds = time(0);
}
Time(int hour, int minute, int second) {
elapseTime = 0;
}
int getHour() {
return hour;
}
// do the getsec...
void setTime(int elapseTime) {
}
void time(int h, int m, int s, int e){
int currents, currentm, currenth;
m = e / 60;
h = m / 60;
currents = e % 60;
currentm = m % 60;
currenth = h % 24;
}
};
int main()
{
return 0;
}
Ill rate the first correct answer! Thanks
Solution
 //Time.h
 //Time Header file
 #ifndef TIME_H
 #define TIME_H
 //Time class declaration
 class Time
 {
 private:
    //private variables
 int hour;
 int minute;
 int second;
public:
    //default constructor of Time
 Time();
 //parameterized constructor
 Time(int elapseTime);
 Time(int h, int m, int s);
 
 //Method declaration
 void setTime(int elapseTime);
 int getHour();
 int getMinute();
 int getSecond();
 
 };
 #endif TIME_H
 ---------------------------------------------------------------------------------
//Time.cpp
 #include<iostream>
 #include<ctime>
 #include \"Time.h\"
 using namespace std;
 Time::Time()
 {
    //time(0) returns the system time in seconds
    setTime(time(0));
 }
//parameterized constructor takes time in seconds
 Time::Time(int elapseTime)
 {
    //user to set user given seconds to time object
    setTime(elapseTime);
 }
//contructor takes hours,minutes and seconds
 Time::Time(int h, int m, int s)
 {
    hour = h;
    minute = m;
    second = s;
 }
//Method that sets the time in terms of seconds, mintues and hours
 void Time::setTime(int elapseTime)
 {
    // Obtain the total seconds since the midnight, Jan 1, 1970
    int totalSeconds = elapseTime;
   // calculate the seconds in totalSeconds %60
    second = totalSeconds % 60;
   // Get remaining minutes
    int totalMinutes = totalSeconds / 60;
   // calculate the minutes in totalSeconds %60
    minute = totalMinutes % 60;
   // Obtain the total hours from totalMinutes/60
    int totalHours = totalMinutes / 60;
   // calculate the hours from remianing totalHours
    hour = (int)(totalHours % 24);
 }
int Time::getHour()
 {
    return hour;
 }
int Time::getMinute()
 {
    return minute;
 }
int Time::getSecond()
 {
    return second;
 }
 ---------------------------------------------------------------------------------
/**
 Test cpp program that prints the current time
 and user set time to console.
 */
 //test.cpp
 #include<iostream>
 //include Time.h header files
 #include \"Time.h\"
 using namespace std;
 int main()
 {
   //create an instance of Time
 Time currentTime;
 cout<<\"System current time \"<<endl;
 cout << currentTime.getHour() << \":\" << currentTime.getMinute() << \":\" << currentTime.getSecond() << endl;
//Set total seconds
 int totalseconds=555550;
 //create an instance of Time
 Time userTime(totalseconds);
 cout<<\"user set current time \"<<endl;
 cout << userTime.getHour() << \":\" << userTime.getMinute() << \":\" << userTime.getSecond() << endl;
 system(\"pause\");
 return 0;
 }
 
 ---------------------------------------------------------------------------------
  Sample output:
System current time
 7:17:18
 user set current time
 10:19:10




