A.
#include #include using namespace std; class Clock //时钟类的声明 { //私有数据成员 int hp,mp,sp,z; public: //外部接口,公有成员函数 Clock(int z1,int NewH, int NewM, int NewS);//有参构造函数声明 int Get_H() {return hp;} int Get_M() {return mp;} int Get_S() {return sp;} void DispTime(); void AddOneS() { sp++; if(sp>=60) { mp++; sp=0; if(mp>=60) { mp=0; hp++; if(hp>=12) { hp=0; } } } } }; //时钟类成员函数的具体实现 Clock::Clock(int z1,int NewH, int NewM, int NewS) //有参构造函数定义 { hp=NewH; mp=NewM; sp=NewS; z=z1; } //获取时区 void Clock::DispTime() { char a[25][20]={"伦敦","巴黎","开罗","莫斯科","第比利斯","新德里", "阿拉木图","曼谷","北京","东京","悉尼","马加丹","惠灵顿","埃尼维托克岛", "中途岛","夏威夷","阿拉斯加","洛杉矶","亚利桑那","亚特兰大","纽约","加拉加斯", "里约热内卢","中大西洋","佛得角群岛"}; if(z<0) z=12+(12+z+1); cout< cout< cout< } int main() { Clock s,s1(1),s2(8,2),s3(2,2,3),s4(3,2,3,4);/*定义了五个对象,一个是无参、一个是有一个参数、有2个参数、有3个参数、有四个参数的*/ s.DispTime(); s1.DispTime(); s2.DispTime(); s3.DispTime(); s4.DispTime(); cout< system("pause"); system("CLS"); }
B.
#include #include using namespace std; class Clock //时钟类的声明 { //私有数据成员 int hp,mp,sp,z; public: //外部接口,公有成员函数 Clock(int z1=0,int NewH=0, int NewM=0, int NewS=0);//默认构造函数声明 int Get_H() {return hp;} int Get_M() {return mp;} int Get_S() {return sp;} void DispTime(); void AddOneS() { sp++; if(sp>=60) { mp++; sp=0; if(mp>=60) { mp=0; hp++; if(hp>=12) { hp=0; } } } } }; //时钟类成员函数的具体实现 Clock::Clock(int z1,int NewH, int NewM, int NewS)//默认构造函数定义 { hp=NewH; mp=NewM; sp=NewS; z=z1; } //获取时区 void Clock::DispTime() { char a[25][20]={"伦敦","巴黎","开罗","莫斯科","第比利斯","新德里", "阿拉木图","曼谷","北京","东京","悉尼","马加丹","惠灵顿","埃尼维托克岛", "中途岛","夏威夷","阿拉斯加","洛杉矶","亚利桑那","亚特兰大","纽约","加拉加斯", "里约热内卢","中大西洋","佛得角群岛"}; if(z<0) z=12+(12+z+1); cout< cout< cout< } int main() { Clock s,s1(1),s2(8,2),s3(2,2,3),s4(3,2,3,4);/*定义了五个对象,一个是无参、一个是有一个参数、有2个参数、有3个参数、有四个参数的*/ s.DispTime(); s1.DispTime(); s2.DispTime(); s3.DispTime(); s4.DispTime(); cout< system("pause"); system("CLS"); }
C.
#include #include using namespace std; class Clock //时钟类的声明 { //私有数据成员 int hp,mp,sp,z; public: //外部接口,公有成员函数 Clock(int z1,int NewH, int NewM, int NewS);//有参构造函数声明 Clock(){}//无参构造函数定义,执行空语句 int Get_H() {return hp;} int Get_M() {return mp;} int Get_S() {return sp;} void DispTime(); void AddOneS() { sp++; if(sp>=60) { mp++; sp=0; if(mp>=60) { mp=0; hp++; if(hp>=12) { hp=0; } } } } }; //时钟类成员函数的具体实现 Clock::Clock(int z1,int NewH, int NewM, int NewS)//有参构造函数定义 { hp=NewH; mp=NewM; sp=NewS; z=z1; } //获取时区 void Clock::DispTime() { char a[25][20]={"伦敦","巴黎","开罗","莫斯科","第比利斯","新德里", "阿拉木图","曼谷","北京","东京","悉尼","马加丹","惠灵顿","埃尼维托克岛", "中途岛","夏威夷","阿拉斯加","洛杉矶","亚利桑那","亚特兰大","纽约","加拉加斯", "里约热内卢","中大西洋","佛得角群岛"}; if(z<0) z=12+(12+z+1); cout< cout< cout< } int main() { Clock s,s1(1),s2(8,2),s3(2,2,3),s4(3,2,3,4);/*定义了五个对象,一个是无参、一个是有一个参数、有2个参数、有3个参数、有四个参数的*/ s.DispTime(); s1.DispTime(); s2.DispTime(); s3.DispTime(); s4.DispTime(); cout< system("pause"); system("CLS"); }
D.
#include #include using namespace std; class Clock //时钟类的声明 { //私有数据成员 int hp,mp,sp,z; public: //外部接口,公有成员函数 Clock(int z1=0,int NewH=0, int NewM=0, int NewS=0);//默认构造函数声明 Clock() //无参构造函数定义,用系统时间赋值 { SYSTEMTIME sys; GetLocalTime( &sys ); hp=sys.wHour; mp=sys.wMinute; sp=sys.wSecond; z=8; } int Get_H() {return hp;} int Get_M() {return mp;} int Get_S() {return sp;} void DispTime(); void AddOneS() { sp++; if(sp>=60) { mp++; sp=0; if(mp>=60) { mp=0; hp++; if(hp>=12) { hp=0; } } } } }; //时钟类成员函数的具体实现 Clock::Clock(int z1,int NewH, int NewM, int NewS)//默认构造函数定义 { hp=NewH; mp=NewM; sp=NewS; z=z1; } //获取时区 void Clock::DispTime() { char a[25][20]={"伦敦","巴黎","开罗","莫斯科","第比利斯","新德里", "阿拉木图","曼谷","北京","东京","悉尼","马加丹","惠灵顿","埃尼维托克岛", "中途岛","夏威夷","阿拉斯加","洛杉矶","亚利桑那","亚特兰大","纽约","加拉加斯", "里约热内卢","中大西洋","佛得角群岛"}; if(z<0) z=12+(12+z+1); cout< cout< cout< } int main() { Clock s,s1(1),s2(8,2),s3(2,2,3),s4(3,2,3,4); /*定义了五个对象,一个是无参、一个是有一个参数、有2个参数、有3个参数、有四个参数的*/ s.DispTime(); s1.DispTime(); s2.DispTime(); s3.DispTime(); s4.DispTime(); cout< system("pause"); system("CLS"); }