Implement the class Tiktok discussed below. You may assume both iostream and string libraries are included, you may not use any other libraries. There are 60 seconds in a minute, 3600 seconds in an hour, 60 minutes in an hour. The 24-hour clock convention goes from 0:0:0 to 23:59:59. Read everything before starting that way you get a better sense on what member variables you need and how you want to implement the member functions. Note that what we expect to see in the console output is not necessarily what we may want to store as member variables.
It may be useful to recall that the modulus operator “%” can be used to obtain the remainder of integer division, also the “+” operator may be used to concatenate strings, and the function std::to_string(int) takes an integer and returns the string equivalent of that integer, presumably for concatenating a string with an integer.
- Implement the default constructor which sets the initial state of Tiktok to correspond to time 0:00:00 in 24-hour clock convention (or 12:00:00 AM 12-hour clock convention).
- addSeconds adds the number of seconds passed into the function to Tiktok. If the amount of seconds to add is negative do nothing. There is no upper limit to the amount of seconds that can be added.
- addMinutes adds the number of minutes passed into the function to Tiktok. If the amount of minutes to add is negative do nothing. There is no upper limit to the amount of minutes that can be added.
- addHours adds the number of hours passed into the function to Tiktok. If the amount of hours to add is negative do nothing. There is no upper limit to the amount of hours that can be added.
- display24 prints to the console the time stored in Tiktok using 24-hour convention; with the following format: XX:XX:XX, followed by a newline.
- display12 prints to the console the time stored in Tiktok using 12-hour convention. It will print AM or PM appropriately; with the following format XX:XX:XX XM, followed by a newline
- Below is the class definition for Tiktok, presumably in some header file. After planning out your design declare your member variables in the private field of the class.
class Tiktok {_x000D_ public:_x000D_ Tiktok(); _x000D_ void addSeconds(int s);_x000D_ void addMinutes(int m);_x000D_ void addHours(int h);_x000D_ void display24() const;_x000D_ void display12() const;_x000D_ _x000D_ private:_x000D_ //TODO: Declare any member variables you think you will need. _x000D_
- Below is example usage for Tiktok :
-
void main() {_x000D_ Tiktok tt; // Declare an instance of Tiktok_x000D_ _x000D_ tt.addHours(48);_x000D_ tt.display12();// 12:0:0 AM_x000D_ tt.display24();// 0:0:0_x000D_ cout << endl_x000D_
tt.addSeconds(60);_x000D_ tt.display12();// 1:0:0 AM_x000D_ tt.display24();// 1:0:0_x000D_ cout << endl;_x000D_
tt.addHours(10);_x000D_ tt.addMinutes(59);_x000D_ tt.addSeconds(59);_x000D_ tt.display12();// 11:59:59 AM_x000D_ tt.display24();// 11:59:59_x000D_ cout << endl;_x000D_
tt.addSeconds(1);_x000D_ tt.display12();// 12:0:0 PM_x000D_ tt.display24();// 12:0:0_x000D_ cout << endl;
tt.addSeconds(11 * 3600 + 12 * 60 + 8); //11hr*3600s/hr + 12m*60s/m + 8s = 40328s_x000D_ tt.display12();// 11:12:8 PM_x000D_ tt.display24();// 23:12:8_x000D_ cout << endl;_x000D_
tt.addMinutes(47);_x000D_ tt.display12();// 11:59:8 PM_x000D_ tt.display24();// 23:59:8_x000D_ cout << endl;_x000D_
tt.addSeconds(52);_x000D_ tt.display12();// 12:0:0 AM_x000D_ tt.display24();// 0:0:0_x000D_ cout << endl;_x000D_
}
Implement the member functions of Tiktok below, assume this being done in a separate source file. Be as neat and syntactically correct as possible.
a) Constructor:
b) addSeconds:
c) addMinutes:
d) addHours:
e) display24:
f) display12: