首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
admin
2021-02-22
26
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
There is a white dog named Hoho.
There is a black dog named Haha.
There is a morley dog named Hihi.
注意:只修改每个/ERROR****found****下的那一行,不要改动程序中的其他内容。
#include
using namespace std;
//狗的颜色:黑、白、黄、褐、花、其他
enum DOGCOLOR{BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER};
class Dog{//狗类
DOGCOLOR color;
char name[20];
static int count;
public:
Dog(char name[],DOGCOLOR color){
strcpy(this->name,name);
//ERROR**********found**********
strcpy(this->color,color);
}
DOGCOLOR getColor()const{return color;}
//ERROR**********found**********
const char*getName()const{return*name;}
const char*getColorStfing()const{
switch(color){
case BLACK:return "black":
case WHITE:return "white":
case YELLOW:return "yellow":
case BROWN:return "brown":
case PIEBALD:return "piebald":
}
return"motley";
}
void show()const{
cout<<"There is a"<
}
};
int main(){
//ERROR**********found**********
Dog dogl("Hoho",WHITE),dog2("Haha",BLACK);dos3("Hihi",OTHER);
dogl.show();
dog2.show();
dog3.show();
return 0;
}
选项
答案
(1)this->color=color; (2)const char getName()const{return*namc!;} (3)Dog dog1(”}toho”,WHITE),dog2(”Haha”,BLACK),dog3("Hihi",OTHER);
解析
(1)主要考查考生对strcpy函数的掌握,如果看到上一条语句strcpy(this->name,Ilame);,就以为本条语句也要用strcpy函数来赋值,这是错误的。strcpy函数只能复制字符串,根据类的私有成员声明可知,color是DOGC()LOR型的,这里直接使用赋值语句“=”即可。
(2)主要考查考生对函数返回值的掌握,先解读语句const char*getName()const{return*name;},要返回的是一个const的字符指针,同时函数内的值不能改变,name在类的私有成员声明中是个字符数组,*flame代表字符数组而不是字符指针,问题就出来了,需要修改返回类型:const char getName()const{return*name;}。
(3)语法错误,定义变量时,变量之间应使用“,”分开。
转载请注明原文地址:https://jikaoti.com/ti/neh0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(intn)的功能是在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个,并作为参数返回。注意:不能修改程序的其他部
有三个关系R、S和T如下:其中关系T由关系R和S通过某种操作得到.该操作为
下列数据结构中,属于非线性结构的是
将数据库的结构划分成多个层次,是为了提高数据库的物理独立性和
学院的每个系都有一名系主任,且一个教师可同时担任多个系的系主任,则实体系主任和实体系间的联系是
定义部门关系模式:部门(部门号,部门名,部门成员,部门总经理),使它不满足第一范式的属性是
有如下头文件:intf1();staticintf2();classMA{public:intf3();staticintf4();};在所描述的函数中,具有隐含
若在表达式y/x中,’’/’’是作为成员函数重载的运算符,则该表达式还可以表示为()。
语句ofstreamf(’’SALARY.DAT’’,ios_base::app);的功能是建立流对象f,并试图打开文件SALARY.DAT与f关联,而且()。
结构化程序设计中,下面对goto语句使用描述正确的是
随机试题
机体处于应激如创伤、手术、感染等情况下,能量代谢的变化中,错误的是
张某在某市开设了三家名称各异的房地产经纪门店,随着不断发展门店数量已经到15家。后来张某决定:把门店的名称和标志统一、管理统一,名称定为甲经纪机构;大量招聘新员工;在未来10年里,大量兼并其他经纪机构,实现企业规模的快速扩张;建立房地产经纪信息计算机管理系
球罐焊接完后应立即进行焊后热处理,其相对更为重要的目的是为了( )。
X企业由甲、乙、丙3位投资者出资共同组建,注册资本是500万元,甲、乙、丙3位投资者持股比例分别为50%,30%和20%。按照公司章程规定,甲、乙、丙3位投资者投入资本分别为250万元、150万元和120万元。X企业已如期收到各投资者的款项。则(
我国证券投资基金的托管人由()来充当。
税收的()是税收的共同原则,在不同的社会制度下为不同阶级服务。
平时嗓门很大的小强,在回答老师提问时声音却很低,老师批评说:“声音这么小,难道你是蚊子么?”话音刚落,全班哄堂大笑。该老师做法()。
尘埃落定白落梅①在世人眼里,林徽因和梁思成又何尝不是郎才女貌,一起留洋深造,一起用现代科学方法研究中国古代建筑。只是那些爱做梦的青年,始终认为林徽因和徐志摩才是最般配的一对。年少的他们不知道现实有多么
设A是n阶正定矩阵,B是n阶反对称矩阵,则矩阵A—B2是①对称阵,②反对称阵,③可逆阵,④正定阵,四个结论中,正确的个数是()
TheLoveofaRobotCancomputerseverreallybelikeus,andifnot,whynot?Thesimilaritiesareobvious.Wecanbothwor
最新回复
(
0
)