首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: There is a
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: There is a
admin
2019-04-24
19
问题
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
There is a white dog named Hobo.
There is a black dog named Haha.
There is a motley 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* get;Name()
const{return*name;}
const char * getColor-string()const{
switch(color){
case BLACK: return "black";
case WHITE: return "white";
case YELLOW: return "yellow";
case BROWN: ret;uEll "brown";
case PTEBALD: return "piebald";
}
return"motley";
}
void show()const{
cout<<"There is a"<
Colorstring() <<" dog named "
<
}
};
int main(){
//ERROR ********found********
Dog dogl("Hoho",WHITE),
dog2("Haha",BLACK);dog3("Hihi",OTHER);
dog1.show();
dog2.show();
dog3.show();
return 0;
}
选项
答案
(1)this->coh)r=color; (2)const char getName()const{return*name;} (3)Dog dogl("Hoho",WHITE),dog2("Haha",BLACK),dog3("Hihi",OTHER);
解析
(1)主要考查考生对strcpy函数的掌握,如果看到上一条语句strcpy(this->name,name);,就以为本条语句也要用strcpy函数来赋值,这是错误的。strcpy函数只能复制字符串,根据类的私有成员声明可知,color是DOGCOLOR型的,这里直接使用赋值语句“=”即可。
(2)主要考查考生对函数返回值的掌握,先解读语句const char * getName()const{return*name;},要返回的是一个const的字符指针,同时函数内的值不能改变,name在类的私有成员声明中是个字符数组,*name代表字符数组而不是字符指针,问题就出来了,需要修改返回类型:eonsl char getName()const{return*name;}。
(3)语法错误,定义变量时,变量之间应使用“,”分开。
转载请注明原文地址:https://jikaoti.com/ti/0st0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
测试用例包括输入值集和______值集。
对于一个类定义,下列叙述中错误的是()。
下面程序的输出结果为()。#inelude<iostream.h>voidmain(){intx;int&y=x;//变量引用y=99;cout<<"x="<<x<<end1;}
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false,则横线处应填上()。Boolfun(char*str){inti=0,j=0;while(str[j])j++;for(j
数据流图中带有箭头的线段表示的是()
不改变关系表中的属性个数但能减少元组个数的是______。
关于运算符重载,下列表述中正确的是()。
假定MyClass为一个类,则该类的拷贝初始化构造函数的声明语句为()
以下哪个不是C++语言中的有效标识符?
下列字符串中,正确的C++标识符是()。
随机试题
下列菌属中属于非发酵菌属的是
关于药品贮藏有关规定的说法,错误的是()。
甲公司自1994年起其生产的衬衫上使用“娇月”商标;1996年,乙公司也开始使用“娇月”商标。乙公司1997年10月向工商行政管理局提出注册商标申请,1998年3月乙公司的“娇月”商标经国家商标局核准注册,其核定使用的商品为服装。1999年1月,乙公司发现
()是指在经济发展过程中,或在工业化的不同阶段上出现的一些影响全局的,在国民经济中居于主导地位的、能带动整个经济增长的产业部门。
划分施工标段时,应考虑的因素包括()。
“两气东输”输送的气体的主要成分是()。
蘑菇管理定律指的是组织或个人对待新进者的一种管理心态。因为初学者常常被置于阴暗的角落,不受重视的部门,只是做一些打杂跑腿的工作,有时还会受到无端的批评、指责、代人受过。组织或个人任其自生自灭,初学者得不到必要的指导和提携,这种情况与蘑菇的生长情景极为相似。
A.worklonghoursB.toclassicalmusicC.emotionsofthepeopleD.ofitsownA.forcedto【T13】______B.Incontrast【T14】___
设平面区域D:(x-2)2+(y-1)2≤1,若比较I1=的大小,则有()
TherearemanysuperstitionsinBritain,butoneofthemost【B1】______heldisthatitisunluckytowalkunderaladder—eveni
最新回复
(
0
)