Advertisement
DacCum

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

Nov 10th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class human {
  7. protected:
  8.     double height;
  9. public:
  10.     virtual void input() = 0;
  11.     virtual void print() = 0;
  12. };
  13.  
  14. class student : human {
  15.     int course;
  16. public:
  17.     void input() {
  18.         cout << "Enter height: ";
  19.         cin >> height;
  20.         cout << "Enter course: ";
  21.         cin >> course;
  22.     }
  23.     void print() {
  24.         cout << "Height: " << height << endl;
  25.         cout << "Course: " << course << endl;
  26.     }
  27. };
  28.  
  29. class person : human {
  30.     string status;
  31. public:
  32.     void input() {
  33.         cout << "Enter height: ";
  34.         cin >> height;
  35.         cout << "Enter status: ";
  36.         cin >> status;
  37.     }
  38.     void print() {
  39.         cout << "Height: " << height << endl;
  40.         cout << "Status: " << status<< endl;
  41.     }
  42. };
  43.  
  44. class teacher : human {
  45.     string lesson;
  46. public:
  47.     void input() {
  48.         cout << "Enter height: ";
  49.         cin >> height;
  50.         cout << "Enter lesson: ";
  51.         cin >> lesson;
  52.     }
  53.     void print() {
  54.         cout << "Height: " << height << endl;
  55.         cout << "Lesson: " << lesson << endl;
  56.     }
  57. };
  58.  
  59. class head_department : human {
  60.     string department;
  61. public:
  62.     void input() {
  63.         cout << "Enter height: ";
  64.         cin >> height;
  65.         cout << "Enter department: ";
  66.         cin >> department;
  67.     }
  68.     void print() {
  69.         cout << "Height: " << height << endl;
  70.         cout << "Department: " << department << endl;
  71.     }
  72. };
  73.  
  74. int main() {
  75.     student s;
  76.     s.input();
  77.     cout << endl;
  78.     s.print();
  79.     cout << endl;
  80.     person p;
  81.     p.input();
  82.     cout << endl;
  83.     p.print();
  84.     cout << endl;
  85.     teacher t;
  86.     t.input();
  87.     cout << endl;
  88.     t.print();
  89.     cout << endl;
  90.     head_department h;
  91.     h.input();
  92.     cout << endl;
  93.     h.print();
  94.  
  95.  
  96.    
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement