题目内容
请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motocar和bicycle作为基类,再派生出motocycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//**********found**********”。#include<iostream.h>classvehicle{private:intMaxSpeed;intWeight;public://**********found**********vehicle(intmaxspeed,intweight):________________~vehicle(){};intgetMaxSpeed(){returnMaxSpeed;}intgetWeight(){returnWeight;}};//**********found**********classbicycle:________publicvehicle{private:intHeight;public:bicycle(intmaxspeedlintweight,intheight):vehicle(maxspeed,weight),Height(height){}intgetHeight(){returnHeight;};};//**********found**********classmotorcar:________publicvehicle{private:intSeatNum;public:motorcar(intmaxspeed,intweight,intseatnum):vehicle(maxspeed,weight),SeatNum(seatnum){)intgetSeatNum(){returnSeatNum;};};//**********found**********classmotorCyCle:________{public:motorcycle(intmaxspeed,intweight,intheight):vehicle(maxspeed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}};voidmain(){motorcyclea(8.0,150,100);cout<<a.getMaxSpeed()<<end1;cout<<a.getWeight()<<end1;cout<<a.getHeight()<<end1;cout<<a.getSeatNum()<<end1;}
查看答案
搜索结果不匹配?点我反馈