首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostream> Using namespace std; class Amc unt{ int amount, public; Amount(int n=0):amount
有如下程序: #inc1ude<iostream> Using namespace std; class Amc unt{ int amount, public; Amount(int n=0):amount
admin
2020-04-07
73
问题
有如下程序:
#inc1ude<iostream>
Using namespace std;
class Amc unt{
int amount,
public;
Amount(int n=0):amount(n){}
Int getAmount()const {return amount,}
Amount &operator +=(Amourit a){
amount+=a.amount,
retum ;
}
};
int main(){
Amount x(3),y(7);
X+=y;
cout<<x.getAmount()<<endl;
return 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/2k8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序用于打印出ASCⅡ字符,其析构函数内的语句应为【 】。#include<iostream.h>#inelude<iomanip,h>template<classT>classArray{
在下列基类的定义中,有无virtual修饰use成员函数的结果将不同,其原因是______。当use()为虚拟函数时的程序执行结果:sizeof(A)=8sized(B)=12sizeof(C)=16当use()
有关析构函数的说法不正确的是()。
有如下程序:#include<iostream>usingnamespacestd;classBase{public:intm,n;};classDerived1:【】Base{};
下面程序的运行结果是#include<iostream.h>intfun(inta[],intn){intresult=1;for(inti=1;i<n;i++)
C++语言中,while循环和do-while循环的主要区别是()。
数据库模型提供了两个映像,它们的作用是()。
将7个数据进行插入排序,在最坏情况下需要比较的次数是
在深度为5的完全二叉树中,叶子结点的个数最多为【 】。
下列选项可以做C++标识符的是
随机试题
(2005年04月)目标市场
TheRaceintoSpaceAmericanmillionaireDennisTitowillalwaysbefamous.Hewasthefirsttouristinspace."Ispentsixt
冠心病搭桥术后早期出现急剧血压下降、心率减慢的最危险因素
单位和个人违反《中华人民共和国传染病防治法》,导致传染病传播、流行,给他人人身造成损害的,应依法
1938年1月6日,新四军军部在南昌成立,并建立新四军驻赣办事处,()任办事处主任。
By,advocatingmoderatechange,theythinkthattheycankeepconsumercostslow.
孟子,姬姓,孟氏,名轲,字子舆;战国时期邹城(今山东邹城市)人。伟大的思想家、教育家。儒家学派的代表人物,与孔子并称“孔孟”。《三宇经》里说:“昔孟母,择邻处。”人们耳熟能详、口耳相传的“孟母三迁”的典故,便出自于此。从哲学方面看,“孟母三迁”所蕴含的哲理
UpdatedSecondEditionByLaurenCollinsNomatterwhereyou’reheadedandwhy,agoodtravelguidebookcanhelpyoumakethemo
GadgetswithaSportingChanceConsumerelectronics:Newsportsequipment,fromtennisracketstorunningshoes,usesproces
Onceuponatime,youbelievedinthetoothfairy.Youcountedonthestabilityofhousingpricesanddependedonbankerstobe,
最新回复
(
0
)