首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请
admin
2017-02-21
21
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程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<iostream>
using namespace std;
class clock
{
public:
Clock(unsigned long i=0);
void set(unsigned long i=0);
void print()const;
void tick(); //时间前进一秒
Clock operator++();
private:
unsigned long total_sec,seconds rminutes,hours,days;
};
Clock∷Clock(unsigned long i)
:total_sec(i),seconds(i%60),
minutes((i/60)%60),
hours((i/3600)%24),
days(i/8 6400){)
void Clock∷set(unsigned long i)
{
total sec=i;
seconds=i%60;
minutes=(i/60)%60;
hours=(i/3600)%60;
days=i/86400;
}
//ERROR *******found*******
void Clock∷print()
{
cout <<days<< "d:" <<hours<<"h:"
<<minutes<< "m:" <<seconds<<"s"<<end1;
}
void Clock∷tick()
{
//ERROR *******found*******
set(total sec++);
}
Clock Clock∷operator++()
{
tick();
//ERROR *******found*******
return this;
}
int main()
{
Clock ck(59);
cout<<"Initial times are"<<end1;
ck.print();
++ck;
cout<<"After 0ne second times are"<<end1;
ck.print();
retuEn 0;
}
选项
答案
(1)void Clock∷pnnt()const (2)set(++total_sec); (3)return * this;
解析
(1)主要考查考生对成员函数的掌握,由Clock类中对函数print的声明void print()const;可知,在定义print函数时少了const。
(2)主要考查考生对++操作的掌握,根据函数要求,时间要先前进一秒,再调用函数set,因此total_see++应改为++total_sec。
(3)主要考查考生对this指针的掌握,函数要求返回值Clock,即返回一个类,而不是指针,因此使用*this。
转载请注明原文地址:https://kaotiyun.com/show/eBAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
为了便于对照检查,测试用例应由输入数据和预期的【】两部分组成。
下面关于构造函数和析构函数的描述,错误的是()。
软件工程研究的内容主要包括【】技术和软件工程管理。
以下哪个特征不是面向对象思想中的主要特征?
下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用;请补充完整。classcomplex{private:intreal;iht
数据流图的类型有______和事务型。
若有以下定义和语句 int a=4,b=3,*p, *q, *w; p=&a; q=&b; w=q; q=NULL; 则以下选项中错误的语句是
数据结构分为线性结构和非线性结构,带链的队列属于______。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
解释下列句中加着重号的词。大凡物不得其平則鳴。
在人性假设理论中,主张领导者给予下属关心、体贴、爱护和尊重,建立团结融洽的人际关系的理论是【】
构成医患之间信任关系的根本前提是
苹果酸脱氢酶的辅酶是GPT(或GOT)的辅酶是
Wearepleasedtoinviteyoutoattendthe14thCanadianCollaborativeMentalHealthCareConference(14thCCMHCC)tobeheldon
举例说明现有器材设备的开发、利用与改造。
公安局以李某寻衅滋事为由,对李某处以15日行政拘留。这种行为属于()。
“只有音乐才能激起人的音乐感,对于没有音乐感的耳朵来说,最美的音乐也毫无意义。”这句话说明:
在培养中西医结合的人才时,要以中医思维为纲,西医思维为目,更要使其全面掌握中、西医的______,学会把二者放在各自所处的大环境、大背景中来______,从全局和整体的角度来寻找二者的相通之处,将中、西医真正地______,形成独具特色的中西医结合医学。填
下面有关视频获取设备的叙述中,错误的是
最新回复
(
0
)