首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹pmjl下的工程pmjl。此工程定义了StopWatch(秒表)类,用于表示时、分、秒信息,有构造函数StopWatch()、设置时间函数reset(),并且重载了前置和后置++运算符,实现增加1秒的功能。 程序
请使用VC6或使用【答题】菜单打开考生文件夹pmjl下的工程pmjl。此工程定义了StopWatch(秒表)类,用于表示时、分、秒信息,有构造函数StopWatch()、设置时间函数reset(),并且重载了前置和后置++运算符,实现增加1秒的功能。 程序
admin
2015-06-27
29
问题
请使用VC6或使用【答题】菜单打开考生文件夹pmjl下的工程pmjl。此工程定义了StopWatch(秒表)类,用于表示时、分、秒信息,有构造函数StopWatch()、设置时间函数reset(),并且重载了前置和后置++运算符,实现增加1秒的功能。
程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
00:00:00
00:01:00
注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include
#include
usingnamespacestd;
classStopWatch//"秒表"类
{
inthours;//小时
intminutes;//分钟
intseconds;//秒
public:
StopWatch():hours(0),minutes(0),
seconds(0){}
voidreset()fhours=minutes=seconds=0;}
StopWatchoperator++(int)//后置++
{
StopWatchold=*this;
++(*this);
returnold;
}
//前进一秒
StopWatch&operator++()//前置++
{
//ERROR*********found*********
if(seconds++=60)
{
seconds=0;minutes++;
if(minutes=60)
{
minutes=0;
hours++;
}
}
//ERROR*********found*********
returnthis;
}
friendvoidshow(StopWatch);
};
voidshow(StopWatchwatch)
{
cout<
cout<
<
<
end1;
}
intmain()
{
StopWatchsw;
show(SW),
for(inti=0;i<59;i++)SW++;
//ERROR*********found*********
show(sw++);
return0;
}
选项
答案
(1)if ((++seconds) == 60) (2)return *this; (3)show(++sw);
解析
(1)主要考查考生对’++’运算符的掌握,结合程序可知,应先使seconds加1,再判断是否需要进位,因此为++second。
(2)主要考查考生对this指针的掌握,应返回this指针指向的类。
(3)主要考查考生对’++’运算符的掌握,判断sw是要先取值再自加1还是先自加1再取值。
转载请注明原文地址:https://kaotiyun.com/show/RxNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#include<iostream>usingnamespacestd;classBase{public:Base(){cout<<"BB";f();}voidf(){c
有如下程序:#include<iostream>usingnamespacestd;classBase{protected:inti;public:intj;};classDeri
在下面的类定义中,横线处应填入的内容是______。classFred{public:voidprint(){cout<<data<<end1;}voidsetData(do
设有如下关系表:RST__________________ABCABCABC112313112223223313则下列操作中正确的是______。
以下程序的输出结果是【】。#include<iostream.h>voidmain(){int*p;p=newint;*p=200;cout<<*p;
排序是计算机程序设计中的一种重要操作,常见的排序方法有插入排序、【】和选择排序等。
若有以下程序:#include<iostream>usingnamespacestd;classA{public:A(inti,intj){a=i;b
在结构化方法中,用数据流程图(DFD)作为描述工具的软件开发阶段是()。
下面4个选项中均是合法的用户标识符的是______。
非成员函数应声明为类的【】函数才能访问这个类的private成员。
随机试题
Justbecausetheycan’tsingoperaorrideabicycledoesn’tmeanthatanimalsdon’thaveculture.There’snobetterexampleof
通常稳定电压为()V的稳压管的温度稳定性较好。
军团菌肺炎首选抗菌药物是()
A.流行性感冒病毒B.腺病毒C.鼻病毒D.链球菌E.柯萨奇病毒流感病原体
撰写“医家五戒十要”的医家是
溶栓治疗者,阿司匹林等抗血小板药物应在溶栓多长时间后使用()。
2010年2月,崔某与同事李某因口角发生纠纷,崔某将李某的胳膊、肩、背、眼多处打伤,除左眼视力每况愈下外,其他损伤经住院治疗均已治愈。李某为此向人民法院提起自诉,人民法院予以受理。经审查,法院认为李某左眼可能致残,被告人可能被判处3年以上有期徒刑的刑罚,遂
某企业为增值税一般纳税人,适用的增值税税率为16%。2018年12月1日,该企业“原材料一甲材料”科目期初结存数量为2000千克,单位成本为15元,未计提存货跌价准备。12月份发生有关原材料收发业务或事项如下:(1)10日,购入甲材料2020千克
我国享有国家立法提案权的国家机关包括
Duringthesummervacation,kidsareoftenseenhanging______inthestreets.(2010-67)
最新回复
(
0
)