首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
admin
2019-08-23
57
问题
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”
#include
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(80,150,100);
cout<
cout<
cout<
cout<
}
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){}; (2)vinual (3)vinual (4)public bicycle,public motorcar
解析
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicIe作为虚基类,避免二义性问题。因此在这里添加vinual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getseatNum函数,由此可知这两个基类都是公有继承,因此得出语句:puhlic bicycle,public motorcar。
转载请注明原文地址:https://www.kaotiyun.com/show/IJ8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行如下程序将输出():#include<iostream>usingnamespacestd;classBase{public:Base(){cout<<"BB";fun();}voi
下面的函数原型非法的是______。
下面关于虚函数的描述中正确的是()。
软件调试的目的是()。
表示C++类中保护成员的关键字是( )。
有如下程序:#includeusingnamespacestd;classTestClass{intn;public:TestClass(intk):n(k){}
有如下的运算符重载函数定义:double operator+(int i,int k){return double(i+k);}但定义有错误,对这个错误最准确的描述是( )。
C++语言的跳转语句中,对于break和continue说法正确的是()。
软件设计模块化的目的是【】。
随机试题
新生儿期保健重要的是帮助小生命度过“营养关”“温度关”和“_______关”。
对账工作的主要内容包括()。
如图所示的电路,欲构成反相积分运算电路,则虚线框1、2内应分别连接()。
根据专利法律制度的规定,下列说法正确的有()。
利润中心不仅对成本负责,也必须对收入和利润负责。()
目前成熟的股票市场普遍采用的发行制度是()。
A、 B、 C、 D、 B
(02年)考虑二元函数的下面4条性质:①f(x,y)在点(x0,y0)处连续;②f(x,y)在点(x0,y0)处的两个偏导数连续;③f(x,y)在点(x0,y0)处可微;④f(x,y)在点(x0,y0)处的两个偏导数存在.若用表示可由性质P推出性
Wherewastheletterprobablyplacedmanyyearsago?
Thispassageisfromapieceof______.Thecenterisanorganizationworkingmainly______.
最新回复
(
0
)