Advertisement
35657

Untitled

May 11th, 2024
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class transport {
  9.  
  10. public:
  11.     transport(int speed, int weight, int payload) : speed_(speed), weight_(weight), payload_(payload){}
  12.  
  13.     int get_speed() {
  14.         return speed_;
  15.     }
  16.  
  17.     int get_weight() {
  18.         return weight_;
  19.     }
  20.  
  21.     int get_payload() {
  22.         return payload_;
  23.     }
  24.  
  25.     virtual void move() = 0;
  26.  
  27. private:
  28.     int speed_; // максимальная скорость (км/ч)
  29.     int weight_; // масса (собственная) (тонн)
  30.     int payload_; // грузоподъемность  (тонн)
  31. };
  32.  
  33. class plane : public transport {
  34.  
  35. public:
  36.     plane(int speed, int weight, int payload, int max_height) : transport(speed, weight, payload), max_height_(max_height) {}
  37.  
  38.     int get_max_height() {
  39.         return max_height_;
  40.     }
  41.  
  42.     void move() {
  43.         cout << "Лечу" << endl;
  44.     }
  45.  
  46. private:
  47.     int max_height_; // максимальная высота (метров)
  48. };
  49.  
  50. class car : public transport {
  51. public:
  52.     car(int speed, int weight, int payload, string transmition) : transport(speed, weight, payload), transmition_(transmition) {}
  53.  
  54.     string get_transmition() {
  55.         return transmition_;
  56.     }
  57.  
  58.     void move() {
  59.         cout << "Еду" << endl;
  60.     }
  61.  
  62. private:
  63.     string transmition_; // тип трансмиссии
  64. };
  65.  
  66. class ship : public transport {
  67.  
  68. public:
  69.     ship(int speed, int weight, int payload, int displacement) : transport(speed, weight, payload), displacement_(displacement) {}
  70.  
  71.     int get_displacement() {
  72.         return  displacement_;
  73.     }
  74.  
  75.     void move() {
  76.         cout << "Плыву" << endl;
  77.     }
  78.  
  79. private:
  80.     int displacement_; // водоизмещение
  81. };
  82.  
  83. int main() {
  84.     setlocale(LC_ALL, "ru");
  85.  
  86.  
  87.     plane pl(800, 200, 30, 10000);
  88.     car cr(200, 2, 1, "manual");
  89.     ship sh(30, 100, 50, 50);
  90.  
  91.     vector<transport*> tr;
  92.  
  93.     tr.push_back(&pl);
  94.     tr.push_back(&cr);
  95.     tr.push_back(&sh);
  96.  
  97.     for (auto a : tr) {
  98.         cout << a->get_payload() << " " << a->get_speed() << " " << a->get_weight() << " ";
  99.         a->move();
  100.         cout << endl;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement