首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填
admin
2021-07-02
104
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:0 最大载重量:12
车牌号:冀 ABC1234 品牌: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<<"座位数:"<
}
};
class Truck:public Aut0Mobile
{//“卡车”类
int max load;//最大载重量
public:
Truck(const char串the brand,const char*the number,int the max load):AutoMobile(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,即strcpy(brand,the_brand);。
(2)主要考查考生对动态分配的掌握情况,参考brand指针的复制过程完成该语句,先给指针number分配空间,通过new来完成:number=new char[aden(the_number)+1];。
(3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数theBrand()来输出品牌。
(4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义:virtual const char*category()const=0;,可知在这里要填写:const{return"卡车";}。
转载请注明原文地址:https://www.kaotiyun.com/show/Ylfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classTestClass{intn:public:TestClass(intk):n(k){}in
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
在下面的类声明中,错误的是
有如下类定义:classTest{intx一,y一;public:Test():a=(0),b—f0){}Test(inta,intb=0):a=(a),b=(b){));若
如果派生类以protected方式继承基类,则原基类的protected成员和public成员在派生类中的访问属性分别是()。
下面不属于软件设计阶段任务的是()。
下列与队列结构有关联的是()。
—棵二叉树共有25个结点,其中5个是叶子结点,则度为l的结点数为()。
若MyTemp是一个只有一个虚拟类型参数的类模板,且有如下语句序列MyTemp<double>p2;MyTemp<long>p3[2];编译系统在处理上面的语句序列时,所生成的模板MyTemp的实例的个数是()。
下列关于类成员对象构造函数调用顺序的叙述中,正确的是()。
随机试题
行政组织变革最直接、最深层的动力是
何谓微生物?微生物有哪些种类?
患者男性,32岁,突发右胸痛,呼吸困难,查体:语音震颤减弱,气管向左侧移位,叩诊右侧为鼓音,该患者查体还可见
对承包商超出设计图纸范围和因承包商原因造成返工的工程量,监理应()。
商业银行在进行客户需求调查时调查的信息包括()。
某县政府为鼓励县属酒厂多创税利,县长与酒厂厂长签订合同约定:酒厂如果完成年度税收100万元的指标,第二年厂长和全厂职工都可以加两级工资。该合同属于什么性质的行为?()
JeffreySachsisnowdevotedtoAccordingtothetext,sustainableeconomy
为计算an的值,某人编写了函数power如下:PrivateFunctionpower(aAsInteger,nAsInteger)AsLong DimsAsLong p=a Fork=1Ton p=p*a Next
Althoughonemightnotthinksofromsomeofthecriticismofit,advertisingisessentialtoourlife.Advertisingisnecessary
A、Itisaboutthesizeofanegg.B、Itiswithabrownskin.C、Itisfullofyellowseeds.D、Itisaboutthesizeofanorange.
最新回复
(
0
)