首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class MyString{ public: char str[80]; MyString(con
有如下程序: #include #include using namespace std; class MyString{ public: char str[80]; MyString(con
admin
2020-11-11
16
问题
有如下程序:
#include
#include
using namespace std;
class 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<
int main(){
MyString x(’abc’),y(’ode’);
cout<<(x+=y)<
return 0;
}
运行这个程序的输出结果是( )。
选项
A、abC
B、cde
C、abcde
D、abccde
答案
D
解析
在类MyString中,定义了带参数的构造函数MyString(const char*s),其作用是把s指向的字符串拷贝到字符组s仃中。在类中还对运算+=进行重载定义,其作用是把字符串str和a相连接并赋给str,所以在主函数中执行x+=y时,结果为ahccde。
转载请注明原文地址:https://kaotiyun.com/show/aayp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹proj2下的工程proj2,其中有元素类Element和队列类Queue的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的输出结果应为:3850507注意:只能在横线处填写适当的代码,不要改动
使用VC6打开考生文件夹proj3下的工程proj3,其中声明了MyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abcde”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:Theval
下列关于常成员的叙述中,正确的是()。
某二叉树共有7个结点,其中叶子结点只有1个,则该二叉树的深度为(假设根结点在第1层)()。
使用VC6打开考生文件夹下的源程序文件modi3.cpp,通过把类Distance定义为类Point的友元类,来实现计算两点之间距离的功能。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。(1)把类CDistance定义为类CPoi
下列关于赋值运算符“=”重载的叙述中,正确的是
将E-R图转换为关系模式时,实体和联系都可以表示为
寸软件系统总体结构图,下面描述中错误的是
随机试题
焊接工艺评定的补加因素是对焊接接头的冲击韧性有影响的因素。
实用性文体在语言表达上不能出现模糊性。
A.热陷心包兼阳明腑实B.邪热留伏阴分C.热与血结,蓄于下焦D.湿阻肠道,传导失司E.余湿未净,胃气不舒湿温病身热不退,脘中微闷,知饥不食,苔薄腻,其病机为
根据《会计法》规定,有()会计违法行为的,可对其直接负责的主管人员和其他直接责任人员处3000元以上5万元以下的罚款。
关于涉税鉴证业务报告的说法,错误的是()。(2015年真题)
相对而言,下列受房地产行业价格波动影响小的行业是()。
甲公司为增值税一般纳税人,适用的增值税税率为17%,存货采用计划成本核算。A材料的计划成本为0.21万元/吨。2018年6月与存货有关的经济业务如下:(1)6月1日,原材料一A材料借方余额为2500万元,材料成本差异贷方余额为300万元。(2)
一条执行考察任务的科考船,现从B地沿河驶向人海口,已知B地距入海口60千米,水速为每小时6千米,若船顺流而下,则用4小时可以到达入海口,该船完成任务从入海口返回并按原速度航行4小时后,由于海水涨潮,水流方向逆转,水速变为每小时3千米,则该船到达B地还需再航
以下资料,回答81-85题外出人口中大专及以上程度的人口占到了:
Airpollutionkilledaboutsevenmillionpeoplelastyear,makingittheworld’ssinglebiggestenvironmentalhealthrisk,theW
最新回复
(
0
)