首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加
admin
2018-03-13
42
问题
请使用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
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 fminutes,hours,days;
};
Clock::Clock(unsigned long i)
:total sec(i),seconds(i%60),
minutes((i/60)%60),
hours((i/3 600)%24),
days(i/8 64 00){}
void Clock::set(unsigned long i)
{
total sec=i;
seconds=i%60;
minutes=(i/60)%60;
hours=(i/3 600)%60 ;
days=i/86400;
}
//ERROR **********found**********
void Clock::print()
{
cout <
<
}
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"<
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/jVAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果是______。#include<iostream>usingnamespacestd;intmain(){intdata=l;int&r=data;
将一个函数声明为一个类的友元函数必须使用关键字______。
在进行任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态;其中只能用于检测输入流状态的操作函数名称是
有如下函数模板定义:template<classT>Tfunc(Tx,Ty){returnx*x*y*y;)在下列对func的调用中,错误的是
有如下程序:#include<iostream.h>usingnamespacestd;classBase{protected:inti:public:intj;
函数定义为Fun(int&i),变量定义n=100,则下面调用正确的是
下列程序的输出结果是#include<iostream>usingnamespacestd;intmain(){chara[]="Hello,World
执行语句序列intn:cin>>n:switch(n){case1:case2:cout<<’1’;case3:case4:cout<<’2’:break;
下面不属于软件工程3个要素的是
______允许用户为类定义一种模式,使得类中的某些数据成员及某些成员函数的返回值能取任意类型。
随机试题
无穷级数=________.(请填写收敛或发散)
60kg体重的正常成年人的血量为
妊娠20周以后,胎儿在子宫内死亡是
抽出的药液,开启的静脉输液用的无菌液体须注明时间,使用应不得超过开启后
5,8,20,68,260,()
根据下列材料,按要求完成任务。材料一《普通高中化学课程标准(实验)》【内容标准】通过实验认识化学反应的速率和化学反应的限度,了解控制反应条件在生产和科学研究中的作用。【活动建议】实验探究:温度、催化剂对过氧化氢分解反应速率的影
1946年2月15日,第一台电子计算机ENIAC在美国宾夕法尼亚大学诞生了。它是为计算弹道和射击表而设计的,上要元件是电子管,每秒钟能完成5000次加法、300多次乘法运算,比当时最快的计算工具快300倍。该机器使用了1500个继电器,18800个电子管占
Topreventthespreadoftheepidemic,thepublichealthorganizationcarriesoutfrequent____________ontherestaurants.
A、Hedoesn’tknowwhattoolstobring.B、Hedoesn’tmindhelpingthewoman.C、Thewomanwon’thavetocarrythetools.D、Thedon
Gettingauniversitydegreeisn’tjustgoodforyourmind—it’sgoodforyourheart,saysanewstudyinthejournalBMC(British
最新回复
(
0
)