怎么把这个程序改成,show()动态联编,可以输出多组数据的?
#include<bits/stdc++.h>
using namespace std;
class vehicle{//车类,作为基类
protected:
int MaxSpeed ,Weight ;
//最大速度,重量
public:
void virtual show(){
};
};
class bicycle: virtual public vehicle {//自行车类:公有继承虚基类vehicle
protected:
int Height ;
//高度
public:
void Setdata1(int ms,int wt,int ht)
{ MaxSpeed=ms; Weight=wt; Height=ht;};
void Show(){
cout<<"公共属性:maxSpeed is"<<MaxSpeed<<",weight is"<<Weight
<<",Bicycle属性:height is"<<Height<<endl;
}
};
class motorcar : public vehicle {//摩托车类:公有继承自行车类和汽车类
protected:
int SeatNum ; //座位数
public:
void Setdata(int ms,int wt,int sn)
{ MaxSpeed=ms; Weight=wt;SeatNum=sn; };
void Show(){
cout<<"公共属性:maxSpeed is"<<MaxSpeed<<",weight is"<<Weight
<<",Vehicle属性:seatNum is"<<SeatNum<<endl;
}
};
main(){
bicycle mt;
motorcar mr;
while(1){
cout<<"Bicycle请输入-0\n"<<"Motocar请输入-1\n"<<"退出结束-2\n";
cout<<"请输入:";
int m;
cin >>m;
int maxspeed1,weight1,height1,seatnum1;
switch(m){
case 0:
cout<<"请输入maxSpeed:" ;
cin>>maxspeed1;
cout<<"请输入weight:";
cin>>weight1;
cout<<"请输入height:";
cin>>height1;
mt.Setdata1(maxspeed1,weight1,height1);
break;
case 1:
cout<<"请输入maxSpeed:" ;
cin>>maxspeed1;
cout<<"请输入weight:";
cin>>weight1;
cout<<"请输入seatNum:";
cin>>seatnum1;
mr.Setdata(maxspeed1,weight1,seatnum1);
break;
case 2:
mt.Show();
mr.Show();
system("pause");
return 0;
}
}
}