c++作业:定义一个time类,内含小时,分钟,秒成员,定义加法函数,实现对time的加法运算
1个回答
展开全部
class time
{private:
int h;
int m;
int s;
time()
{h=0;m=0;s=0;}
public:
int hour()
{return h;}
int minute()
{return m;}
int second()
{return s;}
int sethour(int hour)
{h=hour;}
int sethour(int minute)
{m=minute;}
int sethour(int second)
{s=second;}
time& addtime(time &time1,time &time2)
{ time time3
time3.s=time1.s+time2.s;
time3.m=time1.m+time2.m;
time3.h=time1.h+time2.h;
if (time3.s>=60)
{time3.s=time3.s-60;
time3.m=time3.m+1;
}
if(time3.m>=60)
{time3.m=time3.m-60;
time3.h=time3.h+1;
}
if (time3.h>=24)
time3.h=time3.h-24;
return &time3;
}
}
{private:
int h;
int m;
int s;
time()
{h=0;m=0;s=0;}
public:
int hour()
{return h;}
int minute()
{return m;}
int second()
{return s;}
int sethour(int hour)
{h=hour;}
int sethour(int minute)
{m=minute;}
int sethour(int second)
{s=second;}
time& addtime(time &time1,time &time2)
{ time time3
time3.s=time1.s+time2.s;
time3.m=time1.m+time2.m;
time3.h=time1.h+time2.h;
if (time3.s>=60)
{time3.s=time3.s-60;
time3.m=time3.m+1;
}
if(time3.m>=60)
{time3.m=time3.m-60;
time3.h=time3.h+1;
}
if (time3.h>=24)
time3.h=time3.h-24;
return &time3;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |