#include<iostream>
using namespace std;
int a,b,c;
class Time
{
public :
int setHour()
{
a=hour;
if(0>a||a>12)
a=12;
return a;
}
int setMinue()
{
b=minute;
if(0>b||b>60)
b=0;
return b;
}
int setSecond()
{
c=second;
if(0>c||c>60)
c=0;
return c;
}
void setTime()
{
cin>>hour>>minute>>second;
}
void showTime()
{
if(a<10)
cout<<"0"<<a<<":";
else
cout<<a<<":";
if(b<10)
cout<<"0"<<b<<":";
else
cout<<b<<":";
if(c<10)
cout<<"0"<<c<<endl;
else
cout<<c<<endl;
}
private:
int hour,minute,second;
}t;
int main()
{
//ios::sync_with_stdio(false);
t.setTime();
t.setHour();
t.setMinue();
t.setSecond();
t.showTime();
return 0;
}
Time类的定义
最新推荐文章于 2022-09-08 15:03:43 发布