首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加
admin
2021-09-05
24
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
Initialtimesare
0d:0h:0m:59S
Afteronesecondtimesare
0d:0h:1m:0S
注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include
usingnamespacestd;
clasSClock
{
public:
Clock(unsignedlongi=0);
voidset(unsignedlongi=0);
voidprint()const;
voidtick();//时间前进一秒
Clockoperator++();
private:
unsignedlongtotal_sec,seconds,
minutes,hours,days;
};
Clock::Clock(unsignedlongi)
:totalsec(i),seconds(i%60),
minutes((i/60)%60),
hours((i/3600)%24),
days(i/86400){}
voidClock::set(unsignedlongi)
{
totalsec=i;
seconds:i%60;
minutes=(i/60)%60;
hours=(i/3600)%60;
days=i/86400;
}
//ERROR**********found**********
voidClock::print()
{
cout<
"h:"
<
}
voidClock::tIck()
{
//ERROR**********found**********
set(totalsec++);
}
ClockClock::operator++()
{
tick();
//ERROR**********found**********
returnthis;
}
intmain()
{
Clockck(59);
cout<<"Initialtimesare"<<
end1;
ck.print();
++ck;
cout<<"AfterOnesecondtimes
are"<
ck.print();
return0;
}
选项
答案
(1)voidClock::print()const (2)set(++total_sec); (3)retum*this;
解析
(1)主要考查考生对成员函数的掌握,由Clock类中对函数print的声明voidprint()const;可知,在定义print函数时少了const。
(2)主要考查考生对++操作的掌握,根据函数要求,时间要先前进一秒,再调用函数set,因此total_sec++应改为++total_see。
(3)主要考查考生对this指针的掌握,函数要求返回值Clock,即返回一个类,而不是指针,因此使用*this。
转载请注明原文地址:https://kaotiyun.com/show/cKfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设c1和c2是类MyClass的对象,若将前缀运算符"--"和运算符"/"作为类MyClass的友元函数重载,则表达式--c1/c2等价于
在语句"cout
下列关于return语句的叙述中,正确的是
下列语句中错误的是()。
有如下程序:#includeusingnamespacestd;classAA{public:AA(){cout
请打开考生文件夹下的解决方案文件proj3,本题创建一个小型字符串类,字符串长度不超过100。程序文件包括proj3.h、proj3.epp、writeToFile.obj。补充完成重载赋值运算符函数,完成深复制功能。屏幕上输出的正确结果应该是:Hel
随机试题
特种仓库
下列哪项不支持是肝硬化引起的消化道出血()
善治乳痈的药物是
吸入性损伤的治疗下列哪项最关键
A、川芎B、郁金C、莪术D、姜黄E、延胡索活血行气,止痛的药物是
A.确认为假药B.确认为劣药C.按假药论处D.按劣药论处E.确认为合格药品某药厂生产的西咪替丁胶囊所用原料未取得批准文号,该药品应
为合理保证已发生的采购交易均已记录,需要设置的关键内部控制有()。
授信业务包括()。
人民法院审理上诉行政案件,在哪些情况下必须作出发回重审裁定?()
Thereislittledoubtthattraininghasbecomesuchanacceptedpartofbusinessthatithasreceivedtremendousattentionfrom
最新回复
(
0
)