题目内容 (请给出正确答案)
[主观题]

下面的程序是在str类中重载运算符=,请将程序补充完整,使程序的输出结果为:

he

she

he

he

#include <iostream>

using namespace std;

class str

{

private:

char *st;

public:

str(char *a)

{

set(a);

}

str & perator=(## )

{

delete []st;

set(a.st);

return *this;

}

void show()

{

cout<<st<<endl;

}

~str()

{

delete []st;

}

void set(char *s)

{

st=new char[strlen(s)+1];

strcpy(st,s);

}

};

int main()

{

str s1("he"),s2("she");

s1.show();

s2.show();

##;

s1.show();

s2.show();

}

暂无答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“下面的程序是在str类中重载运算符=,请将程序补充完整,使程…”相关的问题

第1题

如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting:Happy Welcome,请将程序补充完整。

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;

}

点击查看答案

第2题

如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting:Happy Welcome,请将程序补充完整。

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;

}

点击查看答案

第3题

( 14 )如下程序定义了 “ 单词 ” 类 word ,类中重载了 < 运算符,用于比较 “ 单词 ” 的大小,返回相应

辑值。程序的输出结果为: After Sorting: Happy Welcome ,请将程序补充完整。

#include <iostream>

#include <string>

using namespace std;

class Word {

public:

Word(string s) : str(s) { }

string getStr(){ return str; }

【 14 】 const { return (str<w.str); }

friend ostream& operator << (ostream& output, const Word &w)

{ output<<w.str; return output; }

private:

string str;

};

Int main(){

Word w1("Happy"),w2("Welcome");

Cout<<"After sorting: ";

if(w1<w2) cout<<w1<<' '<<w2;

else cout<<w2<<' '<<w1;

return 0;

}

点击查看答案

第4题

下面的程序是在SHUZU类中重载运算符[],程序的运行结果为“B[4]=6”,请将程序补充完整。

#include <iostream>

using namespace std;

class SHUZU

{

private:

int *v;

int s;

public:

SHUZU( int a[], int n );

~SHUZU( )

{

delete []v;

}

int size()

{

return s;

}

int&##(int i);

};

SHUZU::SHUZU(int a[], int n)

{

if( n<=0 )

{

v=NULL;

s=0;

return;

}

s=n;

v= new int ;

for(int i=0; i<n; i++)

v=a;

}

int& SHUZU:perator[](int i)

{

return v;

}

int main()

{

int b[7]={0,2,3,4,6,7,10};

SHUZU B(b,7);

cout<<"B[4]="<<##;

return 0;

}

点击查看答案

第5题

下面程序中对一维坐标点类Point进行运算符重载 #include <iostream> using namespace std; class Point { public: Point(int val) {x=val;} Point & operator++() {x++; return *this; } Point operator++(int) {Point ld = *this; ++(*this); return old;} int GetX() const {return x;} private: int x; }; int main() { Point a(10); cout << (++a).GetX(); cout << a++.GetX(); return 0; }编译和运行情况是

A.运行时输出1011

B.运行时输出1111

C.运行时输出1112

D.编译有错

点击查看答案

第6题

下面程序中对一维坐标点类Point进行运算符重载 #include <iostream> using namespace std; class Point { public: Point(int val) {x=val;} Point & operator++() {x++; return *this; } Point operator++(int) {Point ld = *this; ++(*this); return old;} int GetX() const {return x;} private: int x; }; int main() { Point a(10); cout << (++a).GetX(); cout << a++.GetX(); return 0; }编译和运行情况是

A.运行时输出1011

B.运行时输出1111

C.运行时输出1112

D.编译有错

点击查看答案

第7题

( 33 )下面程序中对一维坐标点类 Point 进行运算符重载

#include

using namespace std;

class point {

public:

point ( int vaI ) {x=val;}

point & operator++ () {x++;retum*this;}

print operator++ ( int ) {point ld=*this,++ ( *this ) ;retum old;}

int GetX () const {retum x;}

private:

int x;

};

int main ()

{

point a ( 10 ) ;

cout<< ( ++a ) .GetX () ;

cout<<A++.GETX () ;

retum () ;

}

编译和运行情况是

A )运行时输出 1011

B )运行时输出 1111

C )运行时输出 1112

D )编译有错

点击查看答案

第8题

下面关于自定义类的运算符重载的说法中,正确的是()。
A.类友元形式重载的运算符,重载函数的参数个数与运算符的实际操作数个数相同

B.类友元形式重载的运算符,重载函数中的this指针指向第一个运算数

C.类友元形式重载的运算符,重载函数中可以直接访问类中的私有成员

D.所有运算符都可以以类友元形式进行重载

点击查看答案

第9题

在MyClass 类的定义中,对赋值运算符=进行重载。请将画线处缺失的部分补充完整。

( ) MyClass::operator=(const MyClass rhs)

{

if(this=&rhs)return*this;

value=rhs. value;

return*this;

}

点击查看答案

第10题

在MyClass类的定义中,对赋值运算符=进行重载。请将横线处缺失的部分补充完整。

______MyClass::operator=(const MyClass&rhs)

{

if(this==&rhs)return*this;

value=rhs.value;

return*this;

}

点击查看答案
热门考试 全部 >
相关试卷 全部 >
账号:
你好,尊敬的上学吧用户
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,
如果您知道正确答案,欢迎您来纠错

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
上学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
上学吧
点击打开微信