这道C++题,不会解答,求详细解答过程
1个回答
展开全部
#include <iostream>
class Time{
friend int Diffence(const Time&,const Time&);
friend void show(const Time&);
public:
Time(int h = 0, int m = 0, int s = 0): Hour(h), Minute(m), Second(s){ }
static int timeToSecond(const Time&);
static int timeBaseDiffence(const Time&);
private:
static int baseHour, baseMinute, baseSecond;
int Hour, Minute, Second;
};
int Time::baseHour = 1;
int Time::baseMinute = 10;
int Time::baseSecond = 10;
int Time::timeToSecond(const Time& t)
{
return t.Hour*3600 + t.Minute*60 + t.Second;
}
int Time::timeBaseDiffence(const Time& t)
{
return timeToSecond(Time(baseHour, baseMinute, baseSecond))
-
timeToSecond(t);
}
int Diffence(const Time& t, const Time& t2)
{
return Time::timeToSecond(t) - Time::timeToSecond(t2);
}
void show(const Time& t)
{
std::cout << t.Hour << " : " << t.Minute << " : " << t.Second;
}
int main()
{
Time t1(0,0,10), t2 (0,0,70); //槽点自找( ̄▽ ̄")
std::cout << Diffence(t1, t2) << std::endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询