12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include <iostream>
- using namespace std;
- class Time {
- private:
- int hours;
- int minutes;
- int seconds;
- public:
- // 构造函数
- Time(int h, int m, int s) {
- hours = h;
- minutes = m;
- seconds = s;
- }
- // 将两个Time对象相加
- void addTime(Time t1, Time t2) {
- seconds = t1.seconds + t2.seconds;
- minutes = t1.minutes + t2.minutes + seconds / 60;
- seconds %= 60;
- hours = t1.hours + t2.hours + minutes / 60;
- minutes %= 60;
- }
- // 输出时间
- void printTime() {
- cout << "the result is:" << hours << ":" << minutes << ":" << seconds << endl;
- }
- };
- int main() {
- int h1, m1, s1, h2, m2, s2;
- cin >> h1 >> m1 >> s1;
- cin >> h2 >> m2 >> s2;
- Time time1(h1, m1, s1);
- Time time2(h2, m2, s2);
- Time result(0, 0, 0);
- result.addTime(time1, time2);
- result.printTime();
- return 0;
- }
|