Advertisement
evcamels

lab_6-var_11

Dec 9th, 2021
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Transport{
  7.     protected:
  8.         string name;
  9.  
  10.     public:
  11.         static Transport * begin;
  12.         Transport * next;
  13.        
  14.         static void add(Transport *cur){
  15.             cur->next = begin;
  16.             begin = cur;
  17.         }
  18.        
  19.         Transport(){
  20.             add(this);
  21.         }
  22.          
  23.     virtual void show(){
  24.         cout << "Transport: " << name << endl;
  25.         cout << "----------------------------" << endl;
  26.     }
  27.    
  28.     virtual void set_parameters(){
  29.         string s;
  30.        
  31.         cout << "Transport: ";
  32.         cin >> s;
  33.        
  34.         name = s;
  35.     }
  36.    
  37.     virtual void print() {
  38.         Transport *l = begin;
  39.        
  40.         while (l) {
  41.             l->show();
  42.             l = l->next;
  43.         }
  44.     }
  45. };
  46.  
  47.         Transport * Transport::begin;
  48.  
  49. class Auto: public Transport{
  50.     protected:
  51.         int horsepower;
  52.         string model;
  53.  
  54.     public:
  55.         Auto():Transport(){}
  56.        
  57.         void show() {
  58.             cout << "Transport: " << name << endl;
  59.             cout << "Horsepower: " << horsepower << endl;
  60.             cout << "Model: " << model << endl;
  61.             cout << "----------------------------" << endl;
  62.         }
  63.        
  64.         void set_parameters() {
  65.             int k;
  66.             string s, a;
  67.            
  68.             cout << "Transport: ";
  69.             cin >> s;
  70.            
  71.             cout << "Model: ";
  72.             cin >> a;
  73.  
  74.             cout << "Horsepower: ";
  75.             cin>>k;
  76.  
  77.             name = s;
  78.             model = s;
  79.             horsepower=k;
  80.         }
  81.      
  82. };
  83.  
  84. class Train: public Transport{
  85.     protected:
  86.         int vagon;
  87.         int weight;
  88.         string type;
  89.  
  90.     public:
  91.         Train():Transport(){}
  92.        
  93.         void show(){
  94.             cout << "Transport: " << name << endl;
  95.             cout << "Vagon: " << vagon << endl;
  96.             cout << "Weight: " << weight << endl;
  97.             cout << "Type:" << type << endl;
  98.             cout << "----------------------------" << endl;
  99.         }
  100.  
  101.         void set_parameters(){
  102.             int n, m;
  103.             string s,y;
  104.            
  105.             cout << "Name: ";
  106.             cin >> s;
  107.            
  108.             cout << "Vagon: ";
  109.             cin >> n;
  110.            
  111.             cout << "Weight: ";
  112.             cin>>m;
  113.            
  114.             cout << "Type: ";
  115.             cin>>y;
  116.            
  117.             name = s;
  118.             vagon = n;
  119.             type = y;
  120.             weight = m;
  121.         }
  122. };
  123.  
  124. class Express: public Transport{
  125.     public:
  126.         Express():Transport(){}
  127. };
  128.  
  129. int main(){
  130.     Transport::begin = 0;
  131.     Transport transport;
  132.     Auto auto_;
  133.     Train train;
  134.     Express express;
  135.  
  136.     cout << "Transport" << endl;
  137.     transport.set_parameters();
  138.    
  139.     cout << "Auto" << endl;
  140.     auto_.set_parameters();
  141.    
  142.     cout << "Train" << endl;
  143.     train.set_parameters();
  144.    
  145.     cout << "Express" << endl;
  146.     express.set_parameters();
  147.    
  148.     cout << endl;
  149.     cout << "All TRANSPORT" << endl;
  150.     cout << endl;
  151.  
  152.     transport.print();
  153.    
  154.     return 0;
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement