xotohop

иерарх_наследование

May 18th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Glider
  6. {
  7.     public:
  8.         string model;       // модель
  9.         string constructor; // конструктор
  10.         string year;        // год разработки
  11.         Glider(string m, string c, string y)
  12.         {
  13.             model = m;
  14.             constructor = c;
  15.             year = y;
  16.         }
  17.         void show()
  18.         {
  19.             cout << "<<----GLIDER---->>" << endl;
  20.             cout << "Model: " << model << endl;
  21.             cout << "Constructor: " << constructor << endl;
  22.             cout << "Year of development: " << year << endl;
  23.         }
  24. };
  25.  
  26. class Airplane : public Glider
  27. {
  28.     public:
  29.         string speed;   // скорость
  30.         string range;   // дальность полета
  31.         Airplane(string m, string c, string y, string s, string r)
  32.                              : Glider(m, c, y), speed(s), range(r)
  33.         {
  34.             model = m;
  35.             constructor = c;
  36.             year = y;
  37.             speed = s;
  38.             range = r;
  39.         }
  40.         void show()
  41.         {
  42.             cout << "<<----AIRPLANE---->>" << endl;
  43.             cout << "Model: " << model << endl;
  44.             cout << "Constructor: " << constructor << endl;
  45.             cout << "Year of development: " << year << endl;
  46.             cout << "Speed: " << speed << endl;
  47.             cout << "Flight range: " << range << endl;
  48.         }
  49. };
  50.  
  51. class Missile : public Airplane
  52. {
  53.     public:
  54.         string purpose; // назначение
  55.         string fuel;    // тип топлива
  56.         Missile(string m, string c, string y, string s, string r, string p, string f)
  57.                                        : Airplane(m, c, y, s, r), purpose(p), fuel(f)
  58.         {
  59.             model = m;
  60.             constructor = c;
  61.             year = y;
  62.             speed = s;
  63.             range = r;
  64.             purpose = p;
  65.             fuel = f;            
  66.         }
  67.         void show()
  68.         {
  69.             cout << "<<----MISSILE---->>" << endl;
  70.             cout << "Model: " << model << endl;
  71.             cout << "Constructor: " << constructor << endl;
  72.             cout << "Year of development: " << year << endl;
  73.             cout << "Speed: " << speed << endl;
  74.             cout << "Flight range: " << range << endl;
  75.             cout << "Purpose: " << purpose << endl;
  76.             cout << "Type of fuel: " << fuel << endl;
  77.         }
  78. };
  79.  
  80. int main()
  81. {
  82.     Glider G1("Perlan 2", "Airbus", "2018");
  83.     Airplane A1("Foxhound", "A. B. Anosovich", "1970s", "920 km/h", "2240 km");
  84.     Missile M1("Phase III Proton Breeze M", "GKNPTS named after M.V. Khrunichev", "2012", "1500 m/s", "65000 km", "Launch vehicle", "Amyl, Heptyl");
  85.     G1.show();
  86.     A1.show();
  87.     M1.show();
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment