第1题
如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting:Happy Welcome,请将程序补充完整。
include
include
using namespace std;
class Word{
public:
Word(string s):str(s){}
string getStr(){retum str;}
【 】const{retum(str
friend ostream&operator$amp;{output$amp;private:
string str:
};
int main(){
Word wl(”Happy”),w2(“Welcome”);
eout$amp;if(w1
}
第2题
include<iostream>
include<string>
using namespace std;
class Word{
public:
Word(strings):str(s){ }
string getStr(){return str;}
______const{return(str<w.str);}
friend ostream& operator<<(ostream& output,const Word &w){output<<w.str;return output;}
private:
string str;
};
int main(){
Word wl("Happy"),w2("Welcome");
cout<<"After sorting:";
if(wl<w2)cout<<w1<<"<<w2;
else cout<<w2<<''<<w1:
return 0;
}
第3题
include<iostream>
include<string>
using namespace std;
class Word{
public:
Word(string s):str(s){}
string getStr(){retum str;}
【 】const{retum(str<w.str);}
friend ostream&operator<<(ostream&output,const W0rd&w)
{output<<w.str;return output;}
private:
string str:
};
int main(){
Word wl(”Happy”),w2(“Welcome”);
eout<<”After sorting:”:
if(w1<w2)tout<<wl<<‘ ’<<w2:
else cout<<w2<<‘ ’<<wl:
return 0;
}
第5题
A.赋值运算符只能作为类的成员函数重载
B.默认的赋值运算符实现了“深层复制”功能
C.重载的赋值运算符函数有两个本类对象作为形参
D.如果已经定义了复制(拷贝)构造函数,就不能重载赋值运算符
第6题
A.赋值运算符只能作为类的成员函数重载
B.默认的赋值运算符实现了“深层复制”功能
C.重载的赋值运算符函数有两个本类对象作为形参
D.如果己经定义了复制(拷贝)构造函数,就不能重载赋值运算符
第7题
A.赋值运算符只能作为类的成员函数重载
B.默认的赋值运算符实现了“深层复制”功能
C.重载的赋值运算符函数有两个本类对象作为形参
D.如果已经定义了复制(拷贝)构造函数,就不能重载赋值运算符
第8题
如果定义了一个类myclass,则为myclass类对象以成员函数形式重载后++运算符的声明应该为()。
A.myclass operator ++();
B.myelass& operator ++();
C.myclass operator++(int);
D.myclass& operator++(int);
第9题
在C++中,如果在类中重载了函数调用运算符(),那么重载函数调用的一般形式为:()。
(A)(表达式)对象
(B)(表达式表)对象
(C)对象(表达式)
(D)对象(表达式表)
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!