Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <set>
- #include <string>
- #include <iostream>
- #include <vector>
- using namespace std;
- class transport {
- public:
- transport(int speed, int weight, int payload) : speed_(speed), weight_(weight), payload_(payload){}
- int get_speed() {
- return speed_;
- }
- int get_weight() {
- return weight_;
- }
- int get_payload() {
- return payload_;
- }
- virtual void move() = 0;
- private:
- int speed_; // максимальная скорость (км/ч)
- int weight_; // масса (собственная) (тонн)
- int payload_; // грузоподъемность (тонн)
- };
- class plane : public transport {
- public:
- plane(int speed, int weight, int payload, int max_height) : transport(speed, weight, payload), max_height_(max_height) {}
- int get_max_height() {
- return max_height_;
- }
- void move() {
- cout << "Лечу" << endl;
- }
- private:
- int max_height_; // максимальная высота (метров)
- };
- class car : public transport {
- public:
- car(int speed, int weight, int payload, string transmition) : transport(speed, weight, payload), transmition_(transmition) {}
- string get_transmition() {
- return transmition_;
- }
- void move() {
- cout << "Еду" << endl;
- }
- private:
- string transmition_; // тип трансмиссии
- };
- class ship : public transport {
- public:
- ship(int speed, int weight, int payload, int displacement) : transport(speed, weight, payload), displacement_(displacement) {}
- int get_displacement() {
- return displacement_;
- }
- void move() {
- cout << "Плыву" << endl;
- }
- private:
- int displacement_; // водоизмещение
- };
- int main() {
- setlocale(LC_ALL, "ru");
- plane pl(800, 200, 30, 10000);
- car cr(200, 2, 1, "manual");
- ship sh(30, 100, 50, 50);
- vector<transport*> tr;
- tr.push_back(&pl);
- tr.push_back(&cr);
- tr.push_back(&sh);
- for (auto a : tr) {
- cout << a->get_payload() << " " << a->get_speed() << " " << a->get_weight() << " ";
- a->move();
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement