#include<iostream>
#include<string>
using namespace std;
class Time{
public:
Time(int h=0,int m=0,int s=0); //定义构造函数
Time operator +(Time&); //运算符“+”重载为友元函数
void disptime(string); //定义普通输出成员函数
private:
int hour;
int minutes;
int seconds;
};
Time::Time(int h,int m,int s) //构造函数
{
hour=h;
minutes=m;
seconds=s;
}
Time Time::operator +(Time& t) //运算符“+”重载为友元函数
{
Time temp;
temp.seconds=seconds+t.seconds;
temp.minutes=minutes+t.minutes;
temp.hour=hour+t.hour;
if(temp.seconds >=60)
{
temp.minutes=temp.minutes+1;
temp.seconds=temp.seconds-60;
}
if(temp.minutes >=60)
{
temp.hour=temp.hour+1;
temp.minutes=temp.minutes-60;
}
return temp;
}
void Time::disptime(string str) //输出成员函数
{
cout<<str;
cout<<hour<<"时"<<minutes<<"分"<<seco