首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填
admin
2021-02-22
40
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
车牌号:冀ABCl234 品牌:ForLand类别:卡车 当前档位:0最大载重量:12
车牌号:冀ABCl234 品牌:ForLand类别:卡车 当前档位:2最大载重量:12
车牌号:沪XYZ5678品牌:QQ类别:小轿车 当前档位:0座位数:5
车牌号:沪XYZ5678品牌:QQ类别:小轿车 当前档位:一1座位数:5
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
#include
#include
using namespace std;
class AutoMobile{ //“汽车”类
char*brand; //汽车品牌
char*number; //车牌号
int speed; //档位:1、2、3、4、5,空档:0,
倒档:一1
public:
AutoMobile(const char*the brand,
const char*the_number):speed(0){
brand=new char[strlen(the
brand)+1 ];
//**********found**********
_________;
//**********found**********
_________;
strcpy(number,the number);
}
~AutoMobile(){delete[]brand;
delete[]number;)
const char*theBrand()const{return brand;} //返回品牌名称
const char*theNumber()const{return number;) //返回车牌号
int currentSpeed()const{ return
speed;} //返回当前档位
void changeGearTo(int the_speed)
{ //换到指定档位
if(speed>=一1&&speed<=5)
speed=the_speed;
}
virtual const char*category()
const=0, //类别:卡车、小轿车等
virtual void show()const{
cout<<”车牌号:”<
//********** found**********
<<”品牌:”<<________
<<”类别:”<
<<”当前档位:”<
}
},
class Car:public AutoMobile{
int seats;//座位数
public:
Car(const char*the_brand,const
char*the_number,int the_seats):
AutoMobile(the brand,the number),
seats(the seats){)
int numberOfSeat()const{return
seats;}
//返回座位数
const char*category()const{return”小轿车”;) //返回汽车类别
void show()const{
AutoMobile::show();
cout<<”座位数:tt<
()<
}
},
class Truck:public AutoMobile{//
“卡车”类
int max load;//最大载重量
public:
Truck(const char*the brand,
const char*the number,int the max
load):AutoMobi le(the brand,the
number),max load(the max load){)
int maxLoad()const{return max
load;}//返回最大载重量
//**********found**********
const char*category()________//
返回汽车类别
void show()const{
AutoMobile::show(.);
cout<<”最大载重量:”<
<
}
};
int main(){
Truck truck(”ForLand”,”冀
ABC1234”,12);
truck.show();
truck.changeGearTo(2);
truck.show();
Car car(”QQ”,”沪xYz5678”,5);
car.show();
car.changeGearTo(一1);
car.show();
cout<
return 0;
}
选项
答案
(1)strcpy(brand,the_brand) (2)number=new char[strlen(the_number)+1] (3)theBrand() (4)const{return”卡车”;}
解析
(1)主要考查考生对strcpy函数的掌握情况,在上一条语句程序给brand指针分配了空间,在这里要复制字符串the_brand,即strepy(brand,the—brand);。
(2)主要考查考生对动态分配的掌握情况,参考brand指针的复制过程完成该语句,先给指针number分配空间,通过new来完成:number=new char[strlen(the_number)+1];。
(3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数theBrand()来输出品牌。
(4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义:virtual const char*category()const=0;,可知在这里要填写:const{return”卡车”;}。
转载请注明原文地址:https://kaotiyun.com/show/j6fp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR***found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:The
以下程序中调用cin函数给变量a输入数值的方法是错误的,其错误原因是()。#includevoidmain(){int*p,*q,a,b;p=&a;coutp;}
有如下程序:#includeusingnamespacestd;intfun(charx,chary){if(x>y)returnx;returny;}
下列关于运算符函数的叙述中,错误的是()。
有如下程序:#includeusingnamespacestd;intmain(){intsum=0;for(inti=1;i
学生和课程的关系模式定义为S(S#,Sn,Sd,Dc,SA)(其属性分别为学号、姓名、所在系、所在系的系主任、年龄);C(C#,Cn,P#)(其属性分别为课程号、课程名、先选课);SC(S#,C#,G)(其属性分别学号、课程号
随机试题
试述高碳酸血症的临床表现。
CantheInternethelppatientsjumpthelineatthedoctor’soffice?TheSiliconValleyEmployersForum,asophisticatedgroupo
A.长波B.中波C.短波D.超短波E.微波分米波、厘米波、毫米波统称为
在进度计划实施的调整中,正确的是()。
根据《招标投标法》,下列关于开标要求的说法不正确的是()。
Thephrase"I’dliketo"involves______phenomenon.
【2013年济宁市市属】教育的本质属性是()。
HaveyoueverbeenaskedbyyourChinesefriends,"Whatisyourzodiacsign?"Ifyousay"I’maPig",theyimmediatelyknowyou
InANewLight:LEDsAttheendofthe1800’s,ThomasEdisonintroducedtheincandescentlightbulbandchangedtheworld.R
Sheisvery______aboutherappearance.Halfofhersalarygoestoclothes.
最新回复
(
0
)