首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0): amoun
有如下程序: #inc1ude<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0): amoun
admin
2019-06-12
15
问题
有如下程序:
#inc1ude<iostream>
Using namespace std;
Class Amount{
int amount;
public;
Amount(int n=0): amount(n){}
Int getAmount()const {retum amount;}
Amount &operator+=(Amount a){
amount+=a.amount;
retum ;
}
};
int main(){
Amount x(3),y(7);
x+=y;
cout<<x.getAmount()<<end1;
retum 0;
}
已知程序的运行结果是10,则下划线处缺失的表达式是( )。
选项
A、*this
B、this
C、&amount
D、amount
答案
A
解析
此题考查的是“+”运算符重载和this指针。语句amount+=a.amount;实现3和7的求和得到amount=10,要使程序的输出结果为10,又因为函数的返回值类型为Amount&,所以横线处填入*this。
转载请注明原文地址:https://kaotiyun.com/show/IL8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面关于函数模板的表述中不正确的是()。
若需要把一个函数“voidfun();”定义为一个类TestClass的友元函数,则应在类TestClass的定义中加入一条语句:___________。
下列关于虚函数的描述中,正确的是()。
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为()。
对于枚举类型的定义语句enumWeek{Sun,Tue=3,Fri,Sat=6,Mon};中枚举常量Mon的值为__________。
执行下列语句后,输出结果为__________。inta=0,b=2,c=3;switch(a){case0:switch(b){case1:co
下列关于C++函数的说明中,正确的是()。
下列对重载函数的描述中,()是错误的。
下列选项中,作为是数据库系统的核心的是()。
随机试题
男,20岁。左腰部被刺后伤口持续溢出淡红色液体2小时。查体:P110次/分,BP95/70mmHg。左上腹有压痛,无肌紧张及反跳痛。最重要的治疗措施为
属于苯巴比妥的鉴别反应有
腹部的缝合伤口,出现红肿、压痛、有波动,最主要的处理是( )。【历年考试真题】
银行业金融机构能否有效管理贷款合同,是其经营管理成败和服务水平高低的一个重要标志。
经营者与具有竞争关系的经营者达成的下列协议中,属于反垄断法禁止的有()。
我国义务教育阶段的课程计划应该具有三个特征是()。
简述法律移植的必要性。
千兆以太网比快速以太网有(29)数据传输率和(30)的碰撞域。
Theproblemwithhistoryissimple.Thereistoomuchofit,Andmoreofitcomesalongeveryday.Weneedsomethingthatwillc
A、Cowardly.B、Anxious.C、Lazy.D、Courageous.DM:Whatwouldyoudoifyouheardastrangenoiseinthemiddleofthenight?W:I
最新回复
(
0
)