首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2018-06-19
53
问题
请使用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):Vchicle(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<<a.getMaxSpeed( )<<end1;
cout<<a.getWeight( )<<end1;
cout<<a.getHeight( )<<end1;
cout<<a.getSeatNum( )<<end1;
}
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){ }; (2)virtual (3)vinual (4)public bicycle,public motorear
解析
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehiele作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcyele类。在主函数中可以看到motorcyele类的实例a调用getHeight函数和getseatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
转载请注明原文地址:https://kaotiyun.com/show/nAAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
派生类中的成员不能直接访问基类中的()成员。
设有下定义的语句:inta[3][2]={10,20,30,40,50,60};intb[3][2]={10,20,30,40,50,60};则a[1][1]*b[2][1)的结果为()。
下面程序的运行结果是______和______。#include<iostream.h)#defineN10#defines(x)x*x#definef(x)(x*x)voidmain(){inti1,
将x=y*z中的“+”用成员函数重载,“*”用友元函数重载应写为______。
在面向对象方法中,类之间共享属性和操作的机制称为______。
在下面的运算符重载函数的原型中,错误的是()。
下面程序的执行结果是()。#include”iostream.h”voidmain(){int*p,r;p=newin;*p=20;r=sizeof(*p);cout<<r<<endl
静态成员函数没有()。
在下面程序的画线处填上适当的内容,使程序执行后的输出结果为1/2005。#include<iostream>usingnamespacestd;classDate{public:Date(intm
创建对象数组时,对数组的每一个元素都将调用一次构造函数,如果没有显式给出数组元素的初值,则调用默认构造函数,下列程序涉及对象数组的创建和单个对象的创建,其输出结果是______。#include<iostream>usingname
随机试题
A应用广谱抗生素B胸膜腔闭式引流C消除致病原因和脓腔D胸膜纤维板剥除手术E彻底排净脓液,使肺早日复张慢性脓胸的治疗原则
女孩,5岁,门珍诊断为21-三体综合征,其核型分析为46,XX,t(14q21q),最可能属于下列哪种染色体畸变所致
某混合式电站在河道上筑拦河大坝,发电引水渠长10km,大坝至电站厂房间原河道两岸分布有需从河道取水灌溉的农田,其间另有一工业取水口,电站厂房上游1km处有一支流汇人河道。为保障电站运行期间河道基本需水,从大坝下泄的水量应考虑()。
常用的给水处理方法不包括()。
田径运动员赛前小周期训练时,负荷的安排一般采用()。
统计图根据下图,回答126~130题。2003-2006年的进口额与上年相比,增长率超过25%的年份有()
甲、乙两人在一条长100米的直路上来回跑步,甲的速度3米/秒,乙的速度2米/秒。如果他们同时分别从直路的两端出发,当他们跑了10分钟后,共相遇多少次?
A、Heisproudofhishomeland—Scotland.B、Hewearsakilt.C、HeisheadoftheMcDonaldclan.D、HehasalwayslivedinEdinbur
Forthispart,youareallowed30minutestowriteashortessayonshapingahealthypersonality.Youressayshouldincludet
Ofthemillionsofinventions,whataretheeightgreatest?A)I’vedrawnupalist.Andthere’sonethingIknowaboutthis
最新回复
(
0
)