首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
admin
2020-05-14
32
问题
请使用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 motley dog named Hihi.
注意:只修改每个//ERROR ****found****下的那一行,不要改动程序中的其他内容。
#include<iostream>
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->nanle,name);
//ERROR**********found**********
strcpy(this->color,color);
}
DOGCOLOR getColor()const{return color;}
//ERROR**********found**********
const char * getName()const{return * gname;}
const char * ggetColorString()const {
switch(color) {
case BLACK:return"black":
case WHITE:return"white":
case YELLOW:return"yellow";
ease BROWN:return"brown":
case PIEBALD:return"piebald":
}
return"motley";
}
void show()const {
cout<<"There is a"<<getColorString()<<"dog named"<<name<<’.’<<end1;
}
};
int main() {
//ERROR**********found**********
Dog dog1("Hoho",WHITE),dog2("Haha",BLACK);dog3("Hihi",OTHER);
dog1.show();
dos2.show();
dog3.show();
return 0;
}
选项
答案
(1)this->color=olor: (2)cons!chat getName( )const{return * name;} (3)Dog dog1("Hoho",WHITE).doa2 ("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代表字符数组而不是字符指针,问题就出来了,需要修改返回类型:const char getName( )const{return * name;}。
(3)语法错误,定义变量时,变量之间应使用“,”分开。
转载请注明原文地址:https://kaotiyun.com/show/Rg8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在一个类体的下列声明中,下确的纯虚函数声明星
下列程序的运行结果是【 】。#include<iostream.h>classSomeClass{public:SomeClass(intvalue){some_value=value;};
线性表的顺序存储结构和线性表的链式存储结构分别是()。
一个函数功能不太复杂但要求被频繁调用,应选用
以下选项中,()是合法的用户标识符。
算法的时间复杂度是指()。
operator是运算符重载时必须使用的关键字,它和被重载的运算符连在一起,作为运算符函数的专用函数名,务必把该函数说明为______ 的。
下列关于栈的描述中错误的是()。
“图形”类Shape中定义了纯虚函数CalArea(),“三角形”类Triangle继承了类Shape,请将Triangle类中的CalArea函数补充完整。classShape{public:virtualintCalArea()=0;}
某系统结构图如下图所示该系统结构图中最大扇入是
随机试题
试述外伤性前房积血的并发症及治疗。
A、艾迪生病B、侏儒症C、库欣综合征D、肢端肥大症E、性幼稚症性激素分泌不足可致
执行政府定价或者政府指导价的,在合同约定的交付期限内政府价格调整时,()。
用高级语言来编写的程序()。
下列各项中,( )不属于个人贷款抵押房屋保险的保险标的。
结合实际,谈谈怎样才能创建一个优秀的班集体。
下列有关法的特征的表述,哪项为正确的组合?()①公司章程对公司、股东、董事、监事、经理均有约束力,为人们提供了行为的标准,因而具有法的特征和效力②一位党的干部因受贿被判处刑罚,同时被开除党籍,这些都是法的实施方式的体现
梁朝简文帝诗云:“紫燕跃武,赤兔越空。”两句中赤兔指良马,紫燕亦指良马。李善注谢灵运诗云:“文帝自代还,有良马九匹,一名飞燕骝。”在古代,武威铜马足下的飞燕无疑是用来比喻良马之神速。这种造型让人一看便知其意,所以铜马应直截了当取名为“紫燕骝”或“飞燕骝”,
中央型腰椎间盘突出症和马尾神经瘤最有意义的鉴别方法是
Whenaneight-lanesteel-truss-archbridgeacrosstheMississippiRiverinMinneapoliscollapsedduringtheeveningrushhouron
最新回复
(
0
)