首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmjl,此工程中包含了类Pets(“宠物”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmjl,此工程中包含了类Pets(“宠物”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
admin
2019-05-22
10
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pmjl,此工程中包含了类Pets(“宠物”)和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
Name:sonny Type:dog
Name:John Type:dog
Name:Danny Type:eat
Name:John Type:dog
注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。
#include
using namespace st:d;
enllm Pets type{dog,cat,bird,fish};
class PetS{
private:
char*name;
Pets_type type;
public:
Pets(const char*flame=”sonny”,
Pets_type type=dog);
Pets&operator=(const Pets&s);
~Pets();
void show()const;
};
Pets::Pets(const char*name,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::operator=(const Pets
&s)
{
if(&s=this)//确保不要向自身赋值
return*this;
delete[]name;
name=new char[strlen(S.name)+
1];
//ERROR*********found*********
strcpy(this一>name,name);
type=S.type;
return*thiS ;
}
void Pets::show()const
{
cout<<”Name:”<
switch(type)
{
case dog:cout<<”dog”;break;
case cat:cout<<”cat”;break;
case bird:cout<<”bird”;break;
case fish:cout<<”fish”;break;
}
cout<
}
int main()
{
Pets mypet1,mypet2(”John”,dog);
Pets youpet(”Danny”,cat);
mypet1.show(),
mypet2.shOW();
youpet.show();
youpet=mypet2;
youpet.show();
return 0;
}
选项
答案
(1)this->type=type; (2)delete[]nal/le; (3)strepy(this->nanle,s.name);
解析
(1)主要考查考生对构造函数的掌握情况,因为形参名和类的私有成员名称都是type,为了避免混淆,所以规定类的私有成员使用this指针调用,即:this一>type=type;。
(2)主要考查考生对析构函数的掌握情况,题目中要求,释放name所指向的字符串。要释放name指针用delete语句,即delete[]name;。
(3)主要考查考生对strepy函数的掌握情况,strcpy函数的形参为两个字符串,而name为指向字符串的指针,因此使用语句:strcpy(this一>nallle,s.name);.
转载请注明原文地址:https://kaotiyun.com/show/ab8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
用白盒法设计测试用例的方法包括()。
下列关于栈的叙述正确的是
在关系代数运算中,__________操作会消去关系中的某些列并删去重复的元组。
A、 B、 C、 D、 CC是传值调用,所以被调函数中形参值改变不会影响到实参,而且没有返回值,所以不会对调用函数产生影响。A是把引用作为函数参数,D是把指针作为函数参数,都属于传地址调用,改变形参均会影响参
A、 B、 C、 D、 C虚函数是在类的声明中使用virtual关键字来限定的成员函数,在成员函数实现时不能再使用virtual关键字进行限定。派生类中的虚函数必须和基类中的虚函数的形参个数、形参类型、返回值
面向对象程序设计主要经历了结构化设计和面向对象的程序设计阶段,面向对象在现在的程序设计中得到广泛的应用。
关系关系代数是关系操纵语言的一种传统表示方式,它以集合代数为基础发展起来的,但它的运算对象和运算结果均是关系,这些新关系仍可以使用同样的代数运算进一步操作。关系代数也是一种抽象的查询语言,它通过对关系的运算来表达查询和修改处理的需求。
下列关于二叉树的叙述中,正确的是()。A)叶子结点总是比度为2的结点少一个B)叶子结点总是比度为2的结点多一个C)叶子结点数是度为2的结点数的两倍D)度为2的结点数是度为1的结点数的两倍
下列有关函数重载的叙述中,错误的是()。
某二叉树共有60个叶子结点与50个度为1的结点,则该二叉树中的总结点数为()。
随机试题
()累计气油比表示油田开发以来天然能量消耗的总和。
正常人尿液镜检每高倍视野红细胞大于______即为镜下血尿,白细胞大于______为脓尿。
患者发生呕血时,常提示一次上消化道出血量达到
参加单位工程验收的人员应具备工程建设相关专业的中级以上技术职称并具有()年以上从事工程建设相关专业的工作经历,参加单位工程验收的签字人员应为各方项目负责人。
《税务行政复议规则(暂行)》在原有税务行政复议制度的基础上,对()首次作出了明确规定。
下列不属于古玩投资特点的是()。
注册会计师对专家信息保密的要求具体是指()。
五声调式中的“五声”指的是()
我国公务员管理的主体是()。
位于青海省西北部,大部分为戈壁、沙漠,东部多沼泽、盐湖,并且为我国地势最高的典型的内陆高原盆地是()。
最新回复
(
0
)