Advertisement
35657

Untitled

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