C++,定义一个时间TIME,能提供和设置有时,分,秒组成的时间,并且编出应用程序.

2024-12-11 15:40:10
推荐回答(2个)
回答1:

#include
using namespcae std;
class time
{ pubilc:
Time(int h, int m, int s);
void SetHour(int h);
void SetMin(int m);
void SetSec(int s);
void OutPutTime();
private:
int hour;
int min;
int sec;
}
Time::Time(int h, int m, int s)
{
hour = h; min = m; sec = s;
}
void Time::SetHour(int h)
{
hour = h;
}
void Time::SetMin(int m)
{
min = m;
}
void Time::SetSec(int s)
{
sec = s;
}
void Time::OutPutTime()
{
cout<}
int main()
{....(最佳答案后补上)
system("pause");
return 0;
}

回答2:

class Time
{
private:
int hour;
int min;
int sec;
public:
Time(int h, int m, int s);
void SetHour(int h);
void SetMin(int m);
void SetSec(int s);
void OutPutTime();
};

Time::Time(int h, int m, int s)
{
hour = h; min = m; sec = s;
}
void Time::SetHour(int h)
{
hour = h;
}
void Time::SetMin(int m)
{
min = m;
}
void Time::SetSec(int s)
{
sec = s;
}
void Time::OutPutTime()
{
cout<}