CC20020419 2022-04-23 07:50 采纳率: 85%
浏览 24
已结题

怎么把这个程序改成,show()动态联编,可以输出多组数据的?

怎么把这个程序改成,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;
}


}
}

   
  
   
  
  

     

   

    
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月1日
    • 创建了问题 4月23日

    悬赏问题

    • ¥15 想用adb命令做一个通话软件,播放录音
    • ¥30 Pytorch深度学习服务器跑不通问题解决?
    • ¥15 部分客户订单定位有误的问题
    • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
    • ¥15 Linux权限管理相关操作(求解答)
    • ¥15 Bug traq 数据包 大概什么价
    • ¥15 在anaconda上pytorch和paddle paddle下载报错
    • ¥25 自动填写QQ腾讯文档收集表
    • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
    • ¥15 android 打包报错