清使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中包含了类Pets(“宠物”) 和主函数main的定义。程序中位于每个“//ERROR****found ****”之后的一行语句有错误,请加以改 正。改正后程序的输出结果应为:
Name:sonny Type:dog
Name:John Type:dog
Name:Danny Typc:cat
Name:John Type:dog
注意:只修改每个“//ERROR ****found ****”下的那一行,不要改动程序中的其他内容。
#include
using namespace sm; enum Pets_type{d09,cat,bird,fish};
class Pets{ private:
char *name; Pets_type type; public:
Pets(const char *name=”sonny”,Pets_type type=dog);
Pets&operator=(const Pets&s);
~Pets();
void show()eonst;};
Pets::Pets(eonst char$naIne,Pets_type type)
//构造函数 {
This ->name=new char[strlen(name)+1];
strcpy(this一>name,name);
//ERROR *********found********* type=type;
}{ Pets::~Pets()//析构函数,释放name所指向的字符串
{ //ERROR *********found********* name=’/0‘;
}
Pets&Pets::0perator=(const Pets&s){
if(&s==this)//确保不要向自身赋值 return *this;
delete[]name;
name=new char[strlen(S.name)+1];//ERROR *********found*********
strcpy(this一>nmne,name); type=S.type:
return *this;}
void Pets::show()const
cout<<“Name:”<<NAME<

发布于 2022-05-13 21:36:48

登录后免费查看答案
关注者
0
被浏览
19
1 个回答
推荐阅读
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看