首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2016-09-20
94
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程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(max,speed,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作为虚基类,避免二义性问题。因此在这里添加vinual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorear和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getH-eight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public mo-torcar。
转载请注明原文地址:https://kaotiyun.com/show/4pNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果是【】。#include<iostream>usingnamespacestd;classTest{public:Test(){cnt++;}~Test(
对于switch(C)中的变量c不能定义为的类型是()。
函数YangHui的功能是把杨辉三角形的数据赋给二位数组的下半三角,形式如下:其构成规律是:①第0列元素和主对角线元素均为1。②其余元素为其左上方和正上方元素值之和。③数据的个数每行递增1。请将程序补充完整。
函数sstrcmp()的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0:当s所指字符串大于t所指字符串时,返回值大于0;当s所指字符串大于t所指字符串时,返回值大于0(功能等同于strcmp())。请填空。intSs
静态成员函数可以直接访问类的【】成员,不能直接访问类的【】成员。
下列有关指针的用法中错误的是()。
下列哪个是C++语言的有效标识符?
在数据库应用系统设计的需求分析阶段,需经过收集资料、分析整理、【】、建立数据字典和用户确认等阶段。
下面内容不属于使用软件开发工具好处的是()。
随机试题
Haveyou【B1】______askedyourselfwhychildrengotoschool?Youwillprobablysaythattheygo【B2】______theirownlanguagea
下列除哪一项外,均为热溶法制备糖浆剂的特点
下图的拱券结构采用了哪种设计手法?
制图综合对制图现象进行的两种基本的处理是()。
人格心理学的主要研究领域有()。
无论是发达国家,还是发展中国家,其幼稚工业或成熟工业一旦被政府所“保护”,就会形成新的既得利益团体,从而对政府产生新的压力,迫使其进一步实施“保护”,使暂时的保护演变为永久的保护。对上面这段话的理解不正确的一项是( )。
Whatproblemdoesthemanmention?
EnvironmenthastakenratherabackseatpoliticallysincetheEarthsummitinRiodeJaneironearlyfiveyearsago.【C1】______th
A、Herpriorschooling.B、Herresidence.C、Herage.D、HerdrivingrecordB
Inrecentyears,therehasbeenabigprice【B1】______betweentheprimaryandsecondarystockmarketsduetodifferentpricing【B2
最新回复
(
0
)