首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
admin
2020-12-21
43
问题
请打开考生文件夹下的解决方案文件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 seatntma):vehicle(maxspeed,weight),SeatNum(seatnum){}
iut getSeatNum(){return SeatNum;};
};
//**********found**********
class motorcycle: ________
{
public:
motorcycle(iut 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()<<endl;
cout<<a.getWeight()<<endl;
cout<<a.getHeight()<<endl;
cout<<a.getSeatNum()<<endl;
}
选项
答案
(1)MaxSpeed(maxspeed),Weighl(weiht){}; (2)v jnual (3)virtual (4)public bjcycle,public motorcar
解析
本题考查vehicle类及其派生类motorcar和bicy—cle,再由这两类派生出motorcycle类,其中涉及构造函数、成员函数和析构函数。构造函数采用成员初始化列表来完成对私有成员的初始化,派生类的书写要注意关键字。 (1)主要考查号生对构造函数的掌握,构造函数使用初始化列表来对私有成员Maxspeed和weight初始化。(2)主要考查号生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加vehicle使vehicle成为虚基类。(3)主要考查考生对派生类的掌握,派生出motorcycle类,在主函数可以看到motorcycle类的实例a调用getHeight函数和getseatNum函数,由此可知这两个基类都垃公有继承,因此得出语句:public bicycle,public motorear。虚基类继承时要添加关键字vinual,以避免二义性。
转载请注明原文地址:https://kaotiyun.com/show/uOyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
语句int*p=&k;定义了指针p,与这个语句等效的语句序列是
有如下程序:#include<iostream>using namespace std;class Point{public: static int number;public: Point(){number++;} ~Point(){n
有如下程序 #include <iostream> using namespace std; int i=1; class Fun { public: static int i; int
有如下程序#include<iostream>usingnamespacestd;classGA{public:virtualintf(){return1;}};classGB:
有如下类定义: class AA { int a; public: int getRef()const{return &a;} //① int getValue()const{
下列有关抽象类和纯虚函数的叙述中,错误的是
有如下程序: #include <iostream> using namespace std; class Part{ public: Part(int x=0):val(x) { cout<<val; }
已知下列语句中的×和y都是int型变量,其中错误的语句是
以下叙述正确的是
如下函数模板:template<classT>Tsquare(Tx){returnx*x;}其中T是()。
随机试题
卵巢表面无腹膜,由单层立方上皮覆盖称生发上皮。
关于卵巢的叙述,正确的是
A.Na+通道开放,产生净Na+内向电流B.Na+通道开放,不产生净Na+电流C.Na+通道关闭,不产生净Na+电流D.K+通道开放,不产生净K+电流膜电位等于K+平衡电位时
患者,男,50岁,肝硬化并发上消化道出血,在使用双气囊三腔管压迫止血期间,突然出现躁动、紫绀、呼吸困难,此时应立即
A.吗啡B.木糖醇C.乳酶生D.硫酸镁E.乳果糖治疗糖尿病患者便秘,慎用的泻药是()。
疏散模型在处理疏散的一般问题时,均采用了三种不同基本方法,不包括()。
某投资者在5月2日以20美元/吨的权利金买入9月份到期的执行价格为140美元/吨的小麦看涨期权合约,同时以10美元/吨的权利金买入一张9月份到期的执行价格为130美元/吨的小麦看跌期权,9月份时,相关期货合约价格为150美元/吨,请计算该投资人的投资结果(
按照我国《商标法》的规定,商标每次续展的有效期为()年。
“能力不如态度。才华不如韧性"。你怎么看?
以下关于抵销的表述正确的是()。
最新回复
(
0
)