首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果
admin
2020-06-29
22
问题
请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
Initial times are
0 d:0 h:0 m:59 s
After one second times are
0 d:0 h:1 m:0 S
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include
using namespace std;
Class Clock
{
public:
Clock(mRsigned long i=0);
void set(unsigned long i=0);
void print()const;
void tick(); //时间前进一秒
Clock operator++();
private:
uns igned long total sec,sec
onds,minutes,hours,days;
};
Clock::C1ock(unsigned long i)
:total sec(i),seconds(i% 60),
minutes((i/60)% 60),
hours((i/3600)% 24),
days(i/86400){}
void Clock::set(uns~gned long i)
{
total sec=i;
seconds=i% 60;
minutes=(i/60)%60 ;
hours=(i/3600)%60 ;
days=i/86400;
}
//ERROR *********found*********
void Clock::print()
{
tout <
hours << "h:"
<
seconds<<"s"<
}
void Clock::tick()
{
//ERROR *********found*********
set(total sec++);
}
C1ock C1ock::operator ++()
{
tick();
//ERROR *******found*******
return this;
}
int main()
{
Clock ck(59);
cout << "Initial times are"
<
ck.print();
++ck;
cout << "After one second
times are" <
ck.print();
return 0;
}
选项
答案
(1)void Clock::print()const (2)set(++total_sec); (3)return*this;
解析
(1)主要考查考生对成员函数的掌握,由Clock类中对函数print的声明void print()const;可知,在定义print函数时少了const。
(2)主要考查考生对++操作的掌握,根据函数要求,时间要先前进一秒,再调用函数set,因此total_sec++应改为++total_sec。
(3)主要考查考生对this指针的掌握,函数要求返回值Clock,即返回一个类,而不是指针,因此使用*this。
转载请注明原文地址:https://kaotiyun.com/show/Ea8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
当用数组元素作函数参数时,这属于【】传递。
在下面横线上填上适当的语句,完成程序。#includeusingnamespacestd;classTestClass{intx;public:TestClass(inti){
以下程序的输出结果是______。#include<iostream.h>#include<string.h>voidmain(){char*p1=",hello",*p2="world!",str[
有如下说明inta[10]={1,2,3,4,5,6,7,8,9,10},*p=a;则数值为9的表达式是
若变量已正确定义并赋值,以下符合C++语言语法的表达式是
下面关于构造函数和析构函数的描述,错误的是()。
软件需求规格说明书应具有完整性、无歧义性、正确性、可验证性、可修改性等特性,其中最重要的是【 】。
下列对重载函数的描述中,错误的是( )。
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序,使该程序输出倒9×9口诀。程序分析:分行与列考虑,共9行9列,设置两个变量i和j,i控制行,j控制列。程序运行结果如下:1*9=9
随机试题
下列选项中,不属于持续整理形态的是()。
A.关节发凉、麻木和酸痛B.关节发热、麻木和酸痛C.关节弹响D.关节肿大E.关节僵硬、畸形类风湿关节炎晚期出现
高分子可吸收接骨板完全吸收的时间为
我国采用的围生期是
(2007年)某理想气体在进行卡诺循环时,低温热源的温度为T,高温热源的温度为nT。则该理想气体在一个循环中从高温热源吸收的热量向低温热源放出的热量之比为()。
将“销售人员”工资表生成记账凭证。选择公式:销售人员.实发合计设置科目:贷方科目:2211—011工资;借方科目:6601—01工资
我国古代宫殿外的陈设品中,表示皇帝公正和至高无上的是()。
2012年上半年世界62个主要产钢国和地区粗钢产量76686万吨,同比增长0.88%,按日均计算仅增长0.32%,扣除我国粗钢产量外日均产量同比下降0.5%。下列选项中,2011年6月粗钢产量高于2011年上半年平均水平的是:
阅读下列材料材料1:大战宣告结束,内战不容再有,如何以建国之功收抗战之果,甚有赖于先生之惠然一行,共定大——1945年8月20日蒋介石再次邀请毛泽东到重庆谈判
A、Sydney.B、Sudan.C、America.D、Britain.D
最新回复
(
0
)