Created
May 23, 2013 05:20
-
-
Save sprintr/5632909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| class Time { | |
| private: | |
| int hours, | |
| minutes, | |
| 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 show() { | |
| cout << hours << ":" << minutes << ":" << seconds << endl; | |
| } | |
| void add(Time t1, Time t2) { | |
| seconds = t1.getseconds() + t2.getseconds(); | |
| if (seconds > 59) { | |
| seconds = seconds - 60; | |
| minutes++; | |
| } | |
| minutes = minutes + t1.getminutes() + t2.getminutes(); | |
| if (minutes > 59) { | |
| minutes = minutes - 60; | |
| hours++; | |
| } | |
| hours = hours + t1.gethours() + t2.gethours(); | |
| if (hours > 23) { | |
| hours = 0; | |
| } | |
| } | |
| }; | |
| int main() { | |
| Time t1(3, 20, 10); | |
| Time t2(4, 30, 20); | |
| Time t3; | |
| t3.add(t1, t2); | |
| t3.show(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment