Create TimeUnit class should be able to hold a time consisting of Minutes and Se
ID: 3532713 • Letter: C
Question
Create TimeUnit class should be able to hold a time consisting of Minutes and Seconds. It should have the following methods:
A constructor that takes a Minute and Second as parameters
ToString() - Should return the string equivilant of the time. "M minutes S seconds."
Test1
Simplify() - This method should take the time and simplify it. If the seconds is 60 seconds or over, it should reduce the seconds down to below 60 and increase the minutes. For example, 2 Min 121 seconds should become 4 minutes 1 second.
Test2
Add(t2) - Should return a new time that is the simplified addition of the two times
Test3
operator + should do the same thing as Add
Test4
pre and postfix ++: should increase the time by 1 second and simplify
Test5
Here is the driver program for your class:
// Just put your TimeUnit class in the same file as your main
void main(){
cout << "Hello World!" << endl;
TimeUnit t1(2,30);
cout << "Time1:" << t1.ToString() << endl;
TimeUnit t2(3,119);
cout << "Time2:" << t2.ToString();
t2.Simplify();
cout << " simplified: " << t2.ToString() << endl;
cout << "Added: " << t1.Add(t2).ToString() << endl;
cout << " t1 + t2: " << (t1 + t2).ToString() << endl;
cout << "Postfix increment: " << (t2++).ToString() << endl;
cout << "After Postfix increment: " << t2.ToString() << endl;
++t2;
cout << "Prefix increment: " << t2.ToString() << endl;
}
Expected Output:
Hello World!
Time1:2 minutes and 30 seconds.
Time2:3 minutes and 119 seconds. simplified: 4 minutes and 59 seconds.
Added: 7 minutes and 29 seconds.
t1 + t2: 7 minutes and 29 seconds.
Postfix increment: 4 minutes and 59 seconds.
After Postfix increment: 5 minutes and 0 seconds.
Prefix increment: 5 minutes and 1 seconds.
Explanation / Answer
when is this due? I'll post link in comment shortly.