首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-05-14
67
问题
请使用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>usingnamespacestd;longfun(intn){if(n>2)return(fun(n-1)+fun(n-2));return
下列程序的输出结果是非曲直【 】。#include<iostream,h>classbase{intx,y;public:base(inti,intj){x=i;y=j;}virtualintadd(){
有如下的类的模板定义:template<classT>classMyClass{private:Tnumber;public:MyClass(Tk);…};
若有以下函数调用语句:f(m+n,x+y,f(m+n,z,(x,y)));在此函数调用语句中实参的个数是()。
有如下程序:#include<iostream.h>Usingnamespacestd;ClassDemo{public:Demo(){cout<<“defaultconstructor\n”;}
下面程序的运行结果是#include"iostream.h"#definesum(a,b)a*bvoidmain(){intx;X=sum(1+2,3);cout<<x;}
已知类X成功地重载了--、=、+、和[]这几个运算符,则其中肯定属于成员函数的运算符是()。
类模板template<classT>classx{...},其中,友元函数f对特定类型T(如int),使函数f(x<int>);成为x<int>模板类的友元,则其说明为()。
若要访问指针变量p所指向的数据,应使用表达式______。
下列运算符中哪些是不能够被重载的?
随机试题
对于深腔壳类零件,可与大气连通的引气装置的作用是
食管癌患者于术后的护理措施正确的是()。
影响全口义齿稳定的主要因素是
乳牙髓腔感染易引起根分叉处骨吸收的原因是()
关于洗钱罪的认定,正确说法是:
某企业为增值税一般纳税人,购入一台不需要安装的设备,增值税专用发票上注明的价款为50000元,增值税税额为8500元,另发生运输费1000元,包装费500元(均不考虑增值税)。不考虑其他因素,该设备的入账价值为()元。
一个单位是否单独设置会计机构,往往取决于()等因素。
关于经营者年薪制,下列说法错误的是()。
1908年8月,清政府颁布(),规定皇帝具有至高无上的权力。
A(n)______allowsuserstoscrambleandunscrambletheirmessageseasilywithoutathirdpartyintruding.
最新回复
(
0
)