首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2017-02-21
65
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<iostream.h>
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//**********found**********
vehicle(int maxspeed,int
weight):_______
~vehicle(){};
int getMaxSpeed() { return MaxSpeed;}
int getWeight() {return
Weight;}
};
//**********found**********
class bicycle:_______public
vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int
weight,int height):vehicle
(maxspeed, weight),Height
(height){)
int getHeight(){ return
Height;};
};
//**********found**********
class motorcar:_______public vehicle
{
private:
int SeatNum;
public:
motorcar(int maxspeed,int weight,int seatnum):vehicle
(maxspeed, weight),SeatNum
(seatnum){}
int getSeatNum(){return SeatNum;};
};
//**********found**********
class motorcycle:_______
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle
(maxspeed, weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}
};
VOid main()
{
motorcycle a(8 0,150,100);
cout<<a.getMaxSpeed() <<end1;
cout<<a.getWeight()<<end1;
cout<<a.getHeight()<<end1;
cout<
}
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){}; (2)virtual (3)virtual (4)public bicycle,public motorcar
解析
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
转载请注明原文地址:https://kaotiyun.com/show/z6Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
软件危机出现于60年代末,为了解决软件危机,入们提出了【】的原理来设计软件,这就是软件工程诞生的基础。
有如下程序#include<iostream.h>#defineN2#defineMN+1#defineNUM2*M+1voidmain()
在C++语言中每个类都有一个【】指针,该指针指向正在调用成员函数的对象。
软件测试的常用方法通常可分为白盒测试和【】。前者是根据程序的内部逻辑来设计测试用例,后者是根据软件的规格说明来设计测试用例。
有如下函数模板的定义:template<classT>Tfunc(Tx,Ty){returnx*x+y*y;}在下列对func的调用中不正确的是
函数定义为Fun(int&i),变量定义n=100.则下面调用正确的是
以下程序中调用cin函数给变量a输入数值的方法是错误的,其错误原因是#include<iostream.h>voidmain(){int*p,*q,a,b;p=&a;
下列语句段中不是死循环的是()。
在一个容量为32的循环队列中,若头指针front=3,尾指针rear=2,则该循环队列中共有______个元素。
执行完下列代码段之后:boolx=true,y=false,z=false;x=x&&y‖z;y=x‖y&&z;z=!(x!=y)‖(y-z);则x=false,y=false,Z=()。
随机试题
信息的加工步骤包括()
Pickouttheappropriateexpressionsfromtheeightchoicesbelowandcompletethefollowingdialoguebyblackeningthecorrespo
下述慢性腹泻的病因中属于感染性因素的是
A、杀酶保苷,便于切片B、增强补脾益气的功能C、降低毒性,保证临床用药安全D、改变药性,扩大药用范围E、消除致泻,增强补肝肾、乌须发作用何首乌蒸制的目的是
简述历史课外读物的主要类型及其相应的教学功能。
人本主义有意义学习有哪些特征?
【B1】【B20】
To:AllemployeesFrom:BenjaminRussekbrussel@hnssoftware.com>Re:ConstructionDearemployees,Iamwritingtoleteveryone
Thebankmanmadeno______(resist)totherobberwithagunpointedathim.
A、Theymoveveryfastthoughthetext.B、Theyvarytheirspeedwhenreading.C、Theyconcentrateonthekeywords.D、Theyre-read
最新回复
(
0
)