首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-05-14
77
问题
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
class vehicle
{
private:
int MaxSpeed;
int Weight;
pubhc:
//**********found**********
vehicle(int maxspeed,int weight):________
~vehicle(){};
int getMaxSpeed(){return MaxSpeed;}
int getWeight(){retum 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:
motorear(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(80,150,100);
cout<
cout<
cout<
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作为基类,再派生出Inotorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicyck,public motorcaro
转载请注明原文地址:https://kaotiyun.com/show/nM8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行语句for(i=1++<4;);,后变量i的值是
有如下程序:#include<iostream>usingnamespacestd;classBase{public:virtualvoidfunc1(){cout<<"Base1";}
类模板template<classT>classx{...},其中,友元函数f对特定类型T(如int),使函数f(x<int>);成为x<int>模板类的友元,则其说明为()。
线性表进行二分法检索,其前提条件是()。
若要访问指针变量p所指向的数据,应使用表达式______。
在C++语言中,访问一个对象的成员所用的运算符是【】,访问一个指针所指向的对象的成员所用的运算符是【】。
重载赋值操作符时,应声明为()。函数。
如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为
若有定义:int*p;则下列各选项中,不同于表达式“*p=*p+1;”的是()。
随机试题
但见悲鸟号古木,雄飞雌从绕林间。号:
关于建设工程施工评标,下列说法中正确的是()。
以下地面测量控制网布设方法的选择,正确的是()。
根据国家旅游行政管理部门对导游人员实行的计分管理办法,下面哪些情况将被扣除10分()
唐代画家________的《________》描绘了贞观年间唐太宗李世民接见吐蕃使者禄东赞的情景。是一幅古代历史画。
Successfulleaders______eventsratherthanreacttothem.
下列不属于全国人大专门委员会的有()。
•Youwillhearabusinesspresentationabout3simplesellingtactics.•Asyoulisten,forquestions1—-12,completethenotes,
Tostaywarmincoldweather,cold-bloodedanimalsmustexposeitselftoasourceofwarmthsuchasdirectsunlight.
A、Toshowhertheplansandexplainindetail.B、Todemonstratehowtousetheproducts.C、Toknowherbetterbeforehiringher.
最新回复
(
0
)