标签:行操作 color pre 客户 处理 函数 整数 初始 构造函数
class clock
{
public:
clock()
{
cout << "尊敬的用户,输入时间时24时60分60秒统一为0时0分0秒" << endl;
hour = 0;
min = 0;
second = 0;
}
void add(int h, int m, int s)
{
int Ssum = (h + hour) * 3600 + (m + min) * 60 + s + second;
hour = Ssum / 3600;
if (hour >= 24) hour = hour - 24;
min = (Ssum - hour * 3600) / 60;
second = Ssum - hour * 3600 - min * 60;
cout << "时间已增加" << endl;
}
void set(int h, int m, int s)
{
if (h >= 24 || m >= 60 || s >= 60) cout << "输入错误" << endl;
if(h<0||m<0||s<0) cout << "输入错误" << endl;
hour = h;
min = m;
second = s;
cout << "时间设置完成" << endl;
}
void show()
{
cout << "现在时间为: "<< hour<<"时"<< min<<"分"<<second <<"秒"<< endl;
}
void reset()
{
hour = 0;
min = 0;
second = 0;
cout << "时间已清零" << endl;
}
void update()
{
second += 1;
if (second >= 60)
{
min += 1;
second -= 60;
}
if (min >= 60)
{
hour += 1;
min -= 60;
}
if (hour >= 24)
{
hour -= 24;
}
cout << "时间已增加一秒" << endl;
}
标签:行操作 color pre 客户 处理 函数 整数 初始 构造函数
原文地址:https://www.cnblogs.com/trainking-star/p/12259101.html