Jommiey

Lektion3_3

Nov 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. class Vehicle
  2. {
  3. public:
  4.   Vehicle(int number_of_wheels = 0, int max_speed = 0)
  5.     : number_of_wheels{number_of_wheels}, max_speed{max_speed}
  6.     {
  7.       if (number_of_wheels > 6)
  8.       {
  9.         max_speed{100};
  10.       }
  11.     }
  12.  
  13.   int get_number_of_wheels() const;
  14.   int get_max_speed() const;
  15.  
  16.   Location& get_start_point() const;
  17.   Location& get_destination() const;
  18.  
  19.   virtual std::string describe_vehicle() = 0;
  20.  
  21. protected:
  22.   int number_of_wheels;
  23.   int max_speed;
  24.   Location start_point; //made-up class Location
  25.   Location destination; //made-up class Location
  26. };
  27.  
  28. class Passenger_Vehicle: public Vehicle
  29. {
  30. public:
  31.   Passenger_Vehicle(int wheels = 0, int speed = 0,
  32.                     int passengers = 0, int doors = 0)
  33.    : Vehicle{wheels, speed},
  34.      numbers_of_passengers{passengers}, number_of_doors{doors}
  35.    {
  36.    }
  37.  
  38.   int get_number_of_passengers() const;
  39.   int get_number_of_doors() const;
  40.  
  41.   std::string describe_vehicle() override
  42.   {
  43.     std::string out{};
  44.     out = out + "Number of wheels: " + std::to_string(number_of_wheels) + "\n";
  45.     out = out + "Top speed: " + std::to_string(max_speed) + "\n";
  46.     out = out + "Number of passengers: " + std::to_string(number_of_passengers);
  47.     out += "\n";
  48.     out = out + "Number of doors: " + std::to_string(number_of_doors) + "\n";
  49.  
  50.     return out;
  51.   }
  52.  
  53. private:
  54.   int number_of_passengers;
  55.   int number_of_doors;
  56. };
  57.  
  58.  
  59. class Freight_Vehicle: public Vehicle
  60. {
  61. public:
  62.   Freight_Vehicle(int wheels = 0, int speed = 0,
  63.                   int payload = 0)
  64.     : Vehicle{wheels, speed}, max_payload{payload}
  65.     {
  66.     }
  67.  
  68.   int get_max_payload() const;
  69.   void load_freight_vehicle();
  70.   Load& unload_freight_vehicle(); //made-up class Load
  71.  
  72.   std::string describe_vehicle() override
  73.   {
  74.     std::string out{};
  75.     out = out + "Number of wheels: " std::to_string(number_of_wheels) + "\n";
  76.     out = out + "Top speed: " std::to_string(max_speed) + "\n";
  77.     out = out + "Max payload: " std::to_string(max_payload) + "\n";
  78.  
  79.     return out;
  80.   }
  81.  
  82. private:
  83.   int max_payload;
  84. };
Advertisement
Add Comment
Please, Sign In to add comment