64,649
社区成员
发帖
与我相关
我的任务
分享
6
6
1. 66 55
2. 6 6
3. 41 1
4. 100 10
居然闲得蛋疼地帮你了。。。
编程题
#include <iostream>
using namespace std;
class Time {
public:
Time() : hour(0), minute(0), second(0){}
Time(int h, int m, int s) : hour(h), minute(m), second(s) {}
friend Time operator+(Time &t1, Time &t2);
void gettime();
private:
int hour;
int minute;
int second;
};
void Time::gettime() {
printf("the time is %d:%d:%d\n", hour, minute, second);
}
Time operator+(Time &t1, Time &t2) {
int h = t1.hour + t2.hour;
int m = t1.minute + t2.minute;
int s = t1.second + t2.second;
m += (s/60), s %= 60;
h += (m/60), m %= 60;
h %= 24;
return Time(h, m, s);
}
int main()
{
Time t1(8, 51, 40);
Time t2(4, 15, 31);
(t1 + t2).gettime();
return 0;
}
后面一题懒得写了
1. 66 55
2. 6 6
3. 41 1
4. 100 10