请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2。本程序中有两个类:一是时间类(Time),用于表示一天中的时间,采用24小时制;另一个是街灯类(StreetLight),用于表示街上的路灯。StreetLight类中有Time类的

admin2015-06-27  29

问题 请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2。本程序中有两个类:一是时间类(Time),用于表示一天中的时间,采用24小时制;另一个是街灯类(StreetLight),用于表示街上的路灯。StreetLight类中有Time类的数据成员。这里对StreetLight类的数据成员和成员函数做一下说明:
intid;//街灯的id
boolison;//街灯的状态,true表示街灯已经开启,false表示街灯关闭
Timecurrenttime;//当前时间
voidturnon();//打开街灯
voidturnoff();//关闭街灯
boolcheck(Timetimethreshold);//判断是否过了可开灯的时间,并需要
//开灯
//(time_threshold)
请在程序中//**********found**********之下一行的横线处填写适当的代码,并删除横线,使程序完整、正确。
输出结果为:
TurnonLight2
给定源程序
#include
usingnamespacestd;
classTime{
private:
inthour;
intminute;
intsecond;
public:
Time(inth,intm,ints){
this->hour=h;
this->minute=m;
thiS->second=s;
}
booloperator>(Time&right)
const{
if(this->hour>right.hour||
(this->hour==right.
hour&&this->minute>right.minute)||
(this->hour==right.hour
&&this->minute==right.minute&&
this->second>right.second))
//**********found**********
________;
returnfalse;
}
};
classStreetLight{
private:
intid;
boolison;
Timecurrenttime;
public:
StreetLight(intid,inthour,intminute,intsecond)
//**********found**********
:________
{
this->ison=false;
this->id=id;
}
voidturnon(){
this->ison=true;
cout<<"TurnonLight"<id<}
voidturnoff(){
//**********found**********
}
boolcheck(Timetimethreshold){
if(this->ison)
returnfalse;
if(currenttime>time
threshold)
returntrue;
//**********found**********
return________;
}
};
intmain(){
StreetLight*lightl=newStreetLight
(1,17,34,45);
StreetLight*light2=newStreetLight
(2,18,34,45);
Timetimethreshold(18,0,0);
if(1ightl->check(time—threshold))
lightl->turn_on();
if(1ight2->check(time_threshold))
light2->turn—on();
return0;
}

选项

答案(1)returntrue; (2)current_time(hour,minute,second) (3)this->is_on=false; (4)false;

解析 (1)主要考查考生对重载操作符的掌握情况,根据需要重载‘>’操作符的含义,当前时间大于开灯时间,返回true。
(2)主要考查考生对构造函数的掌握,StreetLight类在构造函数的成员初始化列表中完成对成员对象current_time的初始化。
(3)主要考查考生对成员函数的掌握,由该函数的功能可知,该函数功能是将灯关闭,设置is_on为false。
(4)主要考查考生对成员函数的掌握,由该函数的功能可知,当灯在关闭的前提下,若当前时间过了开灯时间,则返回true,以此条件判断开灯;其他条件下灯都处于关闭状态,返回false。
转载请注明原文地址:https://kaotiyun.com/show/eIBD777K
0

最新回复(0)