please do not modify the following code: times.cpp result should be : 13 : 12 :
ID: 3822487 • Letter: P
Question
please do not modify the following code:
times.cpp
result should be : 13 : 12 : 22
Brief Program of Time April 20, 2017 at 11:59 pm Instructions Create a class named Time that would be used to store a time expressed in hours, minutes and seconds. Your class should have all the appropri ate constructors and accessor methods. In addition, there should be a method defined as follows: Time add const Time & t) This method should add the time t to the object it is called from. In short, the file times.cpp should work without any errors.Explanation / Answer
Time.h
class Time
{
private:
int hours;
int minutes;
int seconds;
public:
Time()
{
hours = 0;
minutes = 0;
seconds = 0;
}
Time(int h, int m, int s)
{
hours = h;
minutes = m;
seconds = s;
}
int getHours()
{
return hours;
}
int getMinutes()
{
return minutes;
}
int getSeconds()
{
return seconds;
}
void add(const Time &t)
{
int sec = (hours*60 + minutes)*60 + seconds;
int otherSec = (t.hours*60 + t.minutes)*60 + t.seconds;
int totalSec = sec+otherSec;
seconds = totalSec%60;
totalSec = totalSec/60;
minutes = totalSec%60;
hours = totalSec/60;
}
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.