Advertisement
DacCum

ООП лаб 9(2/1)

Nov 10th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class ship {
  7. protected:
  8.     double weight;
  9. public:
  10.     virtual void input() = 0;
  11.     virtual void print() = 0;
  12. };
  13.  
  14. class jet_boat : ship {
  15.     double max_speed;
  16. public:
  17.     void input() {
  18.         cout << "Enter weight: ";
  19.         cin >> weight;
  20.         cout << "Enter max speed: ";
  21.         cin >> max_speed;
  22.     }
  23.     void print() {
  24.         cout << "Weight: " << weight << endl;
  25.         cout << "Max speed: " << max_speed << endl;
  26.     }
  27. };
  28.  
  29. class passenger_liner : ship {
  30.     double number_passengers;
  31. public:
  32.     void input() {
  33.         cout << "Enter weight: ";
  34.         cin >> weight;
  35.         cout << "Enter number of passengers: ";
  36.         cin >> number_passengers;
  37.     }
  38.     void print() {
  39.         cout << "Weight: " << weight << endl;
  40.         cout << "Number of passengers: " << number_passengers << endl;
  41.     }
  42. };
  43.  
  44. int main() {
  45.     jet_boat j;
  46.     j.input();
  47.     cout << endl;
  48.     j.print();
  49.     cout << endl;
  50.     passenger_liner p;
  51.     p.input();
  52.     cout << endl;
  53.     p.print();
  54.  
  55.  
  56.    
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement