首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-05-14
59
问题
请使用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全国计算机二级
相关试题推荐
下列程序的输出结果是非曲直【 】。#include<iostream,h>classbase{intx,y;public:base(inti,intj){x=i;y=j;}virtualintadd(){
执行语句for(i=1++<4;);,后变量i的值是
下面程序的结果是______。#include<iostream.h>classA{public:virtualvoidfun()=0{};};classB:publicA{
下列关于虚函数与函数重载区别的叙述中不正确的是
线性表进行二分法检索,其前提条件是()。
下面是一个栈类的模板,其中push函数将元素i压入栈顶,pop函数弹出栈顶元素。栈初始为空,top值为0,栈顶元素在stack[top-1]中,在下面横线处填上适当语句,完成栈类模板的定义。template<classT>ClassT
已知类Myst有一个只需要一个double型参数的构造函数,且将运算符“-”重载为友元函数。要使语句序列Mystx(3.2),y(5.5),z(0.0);z=8.9-y;y=x-6.3;能够正常运行,运算符函数operator-
数据库系统中实现各种数据管理功能的核心软件是______。
友元运算符obj1>obj2被C++编译器解释为()。
随机试题
行政机关可以成为行政诉讼的原告。()
骨骼摄影距离最佳选择是
关于肝脏功能的叙述,错误的是
下列项目方案类型中,适于采用最小公倍数法进行方案比选的是()。
对于不系统进行风险分析的项目,应根据敏感性分析结果提出相应的减轻不确定因素影响的措施,对项目一级可采取的措施是()。
铁路设施的布置应与城市总体布局相协调,以下对铁路设施安排欠妥的选项为()。
《中华人民共和国建筑法》规定,交付竣工验收的建筑工程,必须符合规定的建筑工程质量标准,有( ),并具备国家规定的其他竣工条件。
PeoplearenotmadetosurviveatthetopofMountEverest.At29,000feet(8,840metres)abovesealevel—justbelowacommercia
有如下程序:#includeusingnamespacestd;classA{public:A(){cout
Whichofthefollowingisnottrue?Theintentionofwritingthearticleis______.
最新回复
(
0
)