抽象类 车.txt

来自「最后声明」· 文本 代码 · 共 56 行

TXT
56
字号
#   include<iostream.h>   
  class   Vehicle{   
  public:   
  virtual   void   get_data(char   *na,char   *col,int   n)=0;   
  virtual   void   display()=0;   
  };   
    
  class   Car:public   Vehicle{   
  private:   
  char   *name;   
  char   *color;   
  int   number;   
  public:   
    void   get_data(char   *na,char   *col,int   n){   
          name=na;   
          color=col;   
          number=n;   
  }   
  virtual   void   display(){   
                        cout<<name<<endl;   
      cout<<color<<endl;   
      cout<<number<<endl;   
    
          }   
  };   
    
  class   Truck:public   Vehicle{   
  private:   
  char   *name;   
  char   *color;   
  int   height;   
  public:   
          void   get_data(char   *na,char   *col,int   n){   
  name=na;   
  color=col;   
  height=n;   
  }   
  virtual   void   display(){   
                        cout<<name<<endl;   
      cout<<color<<endl;   
      cout<<height<<endl;   
          }   
  };   
    
  void   main(){   
  Vehicle   *ptr;   
  Car   car;   
  Truck   truck;   
  ptr=&car;   
  ptr->get_data("BIM","red",4);   
  ptr->display();   
  ptr=&truck;   
  ptr->get_data("东风解放牌卡车","blue",30);   
  ptr->display();   
  }   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?