首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class clock { public: clock( ):seconds(O){ }; clock&o
有如下程序: #include<iostream> using namespace std; class clock { public: clock( ):seconds(O){ }; clock&o
admin
2018-06-19
37
问题
有如下程序:
#include<iostream>
using namespace std;
class clock
{
public:
clock( ):seconds(O){ };
clock&operator++( )
{
this->seconds++;
return * this;
}
void display( )
{
cout<<this->seconds<<’ ’:
private:
int seconds;
};
int main ( )
{
clock c;
++c:
c.display( );
(++(++c)).display( );
c.display( );
return 0;
}
运行后的输出结果是( )。
选项
A、1 3 2
B、1 3 3
C、1 2 3
D、1 2 2
答案
B
解析
main( )函数中首先定义clock类对象c,使用默认构造函数,初始化c的成员seconds为0;然后调用重载的增量运算符函数,将c的成员seeonds自增1,此时c.seconds的值为1;再调用display( )函数输出c.seconds,结果为1;接下来连续两次调用增量运算符函数,将c.seconds增加2,此时c.seconds的值为3,再调用display( )函数输出3,最后再次调用display( )函数输出3,综上运行结果为:1 3 3;本题答案为B。
转载请注明原文地址:https://kaotiyun.com/show/VNAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。boolfun(char*str){inti=0,j=0;while(str[j])_____
在进行任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态;其中只能用于检测输入流状态的操作函数名称是
类模板template<classT>classx{...},其中友元函数f对特定类型T(如int),使函数f(x<int>)成为x<int>模板类的友元,则其说明为()。
有下列二叉树,对此二叉树前序遍历的结果为()。
请将下列栈类Stack补充完整。classStack{private:intpList[100]//int数组,用于存放栈的元素inttop;//栈顶元素(数组下标)public:Stack();top(0){}
以下()成员函数表示纯虚函数。
根据输出结果填空完成下面程序。#include<iostream.h>classTest{private:staticintval;inta;public:staticintfunc()
下面程序的运行结果是______和______。#include<iostream.h)#defineN10#defines(x)x*x#definef(x)(x*x)voidmain(){inti1,
下列数据结构中,属于非线性的是()。
在结构化分析使用的数据流图(DFD)中,利用______对其中的图形元素进行确切解释。
随机试题
教育评估可行性的根本问题是评估的()
在企业开发新产品的各种组织形式中,创业小组主要负责()。
Actually,youcanbe___________youwanttobe,ateacher,adoctor,anastronautoramanagersolongasyousetyourmindtoit
批评:表扬:评价
TheSecuritiesExchangeActof1936establishedtheSecuritiesandExchange(61)(SEC)andgaveitauthority(62)thesecu
Readthearticlebelowaboutmarketresearch.Inmostofthelines(34-45),thereisoneextraword.Itiseithergrammatical
Thekitchenstaffhavetocaterforalldietsfromvegantodiabetic,andfromMuslimtoJewish.Religiousfestivalsarealways
A、Monday.B、Tuesday.C、Wednesday.D、Thursday.C
HowtoFindTimeforYourselfI.Introduction:waystocarveoutyourowntimeA.【T1】______:toobusy【T1】______B.Desire:some
Shortsightcanbe______bytheuseofsuitableglasses.
最新回复
(
0
)