首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0)
有如下程序: #include<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0)
admin
2013-02-27
79
问题
有如下程序: #include<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0):amount(n){} Int getAmount()const{return amount;} Amount &operator+=(Amount a){ amount+=a.amount; return______; } }; int main(){ Amount x(3),y(7); x+=y; cout<<x.getAmount()<<endl; return 0; } 已知程序的运行结果是10,则横线处缺失的表达式是( )。
选项
A、*this
B、this
C、&amount
D、amount
答案
D
解析
此题考查的是“+”运算符重载和this指针。语句 amount+=a.amount;实现3和7的求和得到amount=10,要使程序的输出结果为10,需要把amount的值作为函数的返回值,所以横线处应填入amount。
转载请注明原文地址:https://kaotiyun.com/show/5lVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下说明和定义 intfun(int*C){…} main() { int(*a)(int*)=fun,*b(),X[10],c; … } 则对函数fun的正确调用语句是()。
有以下程序 #include<stdio.h> main() { intk=2,m=4,n=6,*pk=&k,*pm=&m,*p; *(p=&n)=*pk*(*pm); printf("%d\n",n); } 程序运行后的输出
下列叙述中错误的是()。
有以下程序:#include<stdio.h>#include<string.h>structA{inta;charb[10];doublec;};structAf(structAt);main(){structAa
下列关于return语句的叙述中,正确的是()。
有下列程序:#include<stdio.h>main(){charb[]="happychristmas",k;for(k=0-b[k];k++){if(b[k]<'W')b[k]=b[k-]-'a'+'A';printf("%c"
下列选项中不属于结构化程序设计原则的是()。
假定已建立以下数据链表结构,且指针p和q已指向如下图所示的结点:则以下选项中可将q所指结点从链表中删除并释放该结点的语句是()。
数据的组织和存储会直接影响算法的实现方式和【】。
随机试题
评估工作的最后一道程序是()
A.登革热B.黑热病C.莱姆病D.地方性斑疹伤寒E.流行性斑疹伤寒硬蜱传播
治疗肝阳上亢之头痛,不宜选用()。
对于工程项目范围的任何变更,在各方达成一致意见后,由()发出正式的变更令。
下列行为中,构成重大责任事故罪的行为应是()。
依次填入下列各句横线处的词语,恰当的一组是:①陈老师说,这部著作虽语言直白,但内容______,中学生现在还难以理解。②睡前适量的运动可以分散注意力,使紧张的精神______下来,有利于睡眠。③昨晚,湖北武当山突发大火,有着千年历史
Youwillhearatalk.Foreachquestion(23-30),markoneletter(A,BorC)forthecorrectanswer.Afteryouhavelistenedonc
Thepresidentofthecollege,togetherwiththedeans,______aconferenceforthepurposeoflayingdowncertainregulations.
TheNationalTrustinBritain,togetherwithsimilarvoluntaryorganizations,playsanincreasinglyimportantpartinthepreser
IsthereenoughoilbeneaththeArcticNationalWildlifeRefuge(ANWR)tohelpsecure,America’senergyfuture?PresidentBush【B
最新回复
(
0
)