Advertisement
Vladislav_Bezruk

Untitled

Nov 7th, 2021
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. // Створити абстрактний клас «корабель»і похідні від нього «ракетний катер» та «пасажирський лайнер».
  2. // Функції введення та виведення даних в базовому класі зробити абстрактними і визначити їх конкретно в похідних класах.
  3. // Продемонструвати їхню роботу.
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. class ship {
  10.     protected:
  11.         string name;
  12.        
  13.     public:
  14.         virtual void input() = 0;
  15.  
  16.         virtual void output() = 0;
  17. };
  18.  
  19. class pasship : public ship {
  20.         int people;
  21.  
  22.     public :
  23.         void input() {
  24.             cout << "Name of ship: ";
  25.             cin >> name;
  26.  
  27.             cout << "Number of people on board: ";
  28.             cin >> people;
  29.            
  30.             cout << endl;
  31.         }
  32.         void output() {
  33.             cout << "Name of ship: " << name << endl;
  34.             cout << "Number of people on board: " << people << endl;
  35.            
  36.             cout << endl;
  37.         }
  38. };
  39.  
  40. class batleship : public ship {
  41.         int weapon;
  42.  
  43.     public :
  44.         void input() {
  45.             cout << "Name of ship: ";
  46.             cin >> name;
  47.  
  48.             cout << "Number of weapons: ";
  49.             cin >> weapon;
  50.            
  51.             cout << endl;
  52.         }
  53.         void output() {
  54.             cout << "Name of ship: " << name << endl;
  55.             cout << "Number of weapons: " << weapon << endl;
  56.            
  57.             cout << endl;
  58.         }
  59. };
  60. int main() {
  61.     ship *a = new pasship;
  62.  
  63.     cout << "Pasship:" << endl;
  64.     a->input();
  65.     a->output();
  66.  
  67.     a = new batleship;
  68.  
  69.     cout << "Batleship:" << endl;
  70.     a->input();
  71.     a->output();
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement