填空题
类time可以输出12小时或24小时制的时间,现需要设计一个缺省构造函数,缺省值为0时0分0秒。该缺省构造函数为______。
#include<iostream.h>
class Time
{
int h,m,s;
public:
Time(int hour=0,int min=0,int sec=0){settime(hour,min,sec);}
void settime(int hour,int min,int sec){h=hour;m=min;s=sec;}
void show24( )
{ cout<<(h<10"0":"")<<h<<":"<<(m<10"0":"")<<
m<<":"<<(s<10"0":"")<<s<<endl;
}
void showl2( )
{ int temp=(h= =0 || h= =12) 12:h%12;
cout<<(temp<10"0":"")<<temp<<":"<<(m<10"0":"")
<<m<<":"<<(s<10"0":"")<<s<<((temp>0&&h<12)"
AM":"PM")<<endl;
}
};
void main( )
{
Time t(15,43,21);
t.showl2( );
t.show24( );
}
【参考答案】
Time( ){h=0;m=0;s=0;}