首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostream> #inc1ude<cstring> using namespace std; c1ass MyString{ public: char str[80];
有如下程序: #inc1ude<iostream> #inc1ude<cstring> using namespace std; c1ass MyString{ public: char str[80];
admin
2017-06-18
42
问题
有如下程序:
#inc1ude<iostream>
#inc1ude<cstring>
using namespace std;
c1ass MyString{
public:
char str[80];
MyString(const char*s){ strcpy(str,s);)
MyString& operator+=(MyString a){
strcat(str,a.str),
return *this;
}
};
ostream& operator<<(ostream& s,const MyString& z){return s<<z.str;}
int main(){
MyString x("abc"),y("cde");
cout<<(x+=y)<<end1;
return 0;
}
运行这个程序的输出结果是( )。
选项
A、abc
B、cde
C、abcde
D、abccde
答案
D
解析
在类MyString中,定义了带参数的构造甬数MyString(const char*s),其作用是把s指向的字符串拷贝到字符组str中。在类中还对运算+=进行重载定义,其作用是把字符串str和a相连接并赋给str,所以在主函数中执行x+=y时,结果为abccde。
转载请注明原文地址:https://kaotiyun.com/show/cmAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的执行结果是【 】。#include<iostream.h>classMyclass{public:voidGetSum(inta)stat
下列程序的运行结果是( )。 #include<iostream.h> voidfun(int &a,int b=3) { static int i=2; a=a+b+i; i=i+a; } void ma
有如下程序: #include<iostream> using namespace std; class VAC{ public: int f() const{return 3;} int f() {
作为成员函数重载的运算符,第一操作数就是参数表中隐含的________所指向的对象,因此并不显示地出现在参数表中。
下列关于成员函数特征的描述中,错误的是()。
关于new运算符的错误的描述是()。
已知n是一个int型变量,下列语句中错误的是
关于类和对象描述错误的是
类classone在声明func成员函数时发生错误,出错原因是【 】。Classone{private:inta;
随机试题
Nobodyhastaughthimhowtoactwellonthestage.
Whenpeoplearestruckbylightening,theyfalltothegroundasthoughtheywerestruckbyasevereblowtothehead.Afterthe
建设项目竣工环境保护验收是指建设项目竣工后,环境保护行政主管部门根据《建设项目竣工环境保护验收管理办法》规定,依据环境保护验收监测或调查结果,并通过()等手段,考核该建设项目是否达到环境保护要求的活动。
跟单员在处理样品时应注意的事项是()
某公司债券面值100元,票面利率为8%,每年付息,到期期限10年。如果将债券的利息单独作为证券出手,并且投资者要求的收益率为9%,那么该“利息证券”的发行价格为______。
张女士为A市甲超市财务管理人员,她从2014年1月份开始建立家庭消费电子账,6月份从甲超市购买了下列商品:(1)粉底液一盒,支出400元。(2)白酒1000克,支出640元。(3)食品支出1010元,其中:橄榄油2500克,支出400元;
马克思主义政治经济学的研究对象是社会生产力及其发展规律。
Myfive-year-olddaughterknewexactlywhatshewantedforChristmasof1977,andtoldmeso.Yes,shestillwouldlikethepink
Wheredoyoureallycomefrom?Andhowdidyouget(1)whereyoulivetoday?DNAstudiessuggestthatallhumanstoday(2)from
A、Callforadoctor.B、Buysomemedicine.C、LookforJack.D、SendJacktoschool.A根据对话中男士所说“Sure,I’lldoitrightaway.”可知男士马上要
最新回复
(
0
)