Advertisement
Vladislav_Bezruk

Untitled

Oct 13th, 2021
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Person {
  6.     protected:
  7.         string name;
  8.         int age;
  9.    
  10.     public:
  11.         Person() {}
  12.        
  13.         Person(string n, int a) : name(n), age(a) {}
  14.        
  15.         void setPerson() {
  16.             cout << "Enter info about person: " << endl;
  17.             cout << "\tname: ";
  18.             cin >> name;
  19.             cout << "\tage: ";
  20.             cin >> age;
  21.             cout << endl;
  22.            
  23.             return;
  24.         }
  25.        
  26.         void getPerson() {
  27.             cout << "Info about person: " << endl;
  28.             cout << "\tname: " << name << endl;
  29.             cout << "\tage: " << age << endl << endl;
  30.            
  31.             return;
  32.         }  
  33. };
  34.  
  35. class Employee : public Person {
  36.     protected:
  37.         int salary;
  38.    
  39.     public:
  40.         Employee() {}
  41.        
  42.         Employee(string n, int a, int s) : Person(n, a), salary(s) {}
  43.        
  44.         void setEmployee() {
  45.             cout << "Enter info about employee: " << endl;
  46.             cout << "\tsalary: ";
  47.             cin >> salary;
  48.             cout << endl;
  49.            
  50.             return;
  51.         }
  52.        
  53.         void getEmployee() {
  54.             cout << "Info about employee: " << endl;
  55.             cout << "\tsalary: " << salary << endl << endl;
  56.            
  57.             return;
  58.         }  
  59. };
  60.  
  61. class Servant : public Employee {
  62.     protected:
  63.         int experience;
  64.    
  65.     public:
  66.         Servant() {}
  67.        
  68.         Servant(string n, int a, int s, int e) : Employee(n, a, s), experience(e) {}
  69.        
  70.         void setServant() {
  71.             cout << "Enter info about servant: " << endl;
  72.             cout << "\texperience: ";
  73.             cin >> experience;
  74.             cout << endl;
  75.            
  76.             return;
  77.         }
  78.        
  79.         void getServant() {
  80.             cout << "Info about servant: " << endl;
  81.             cout << "\texperience: " << experience << endl << endl;
  82.            
  83.             return;
  84.         }  
  85. };
  86.  
  87. class Engineer : public Servant {
  88.     string field;
  89.     int level;
  90.    
  91.     public:
  92.         Engineer() {}
  93.        
  94.         Engineer(string n, int a, int s, int e, string f, int l) : Servant(n, a, s, e), field(f), level(l) {}
  95.        
  96.         void setEngineer() {
  97.             cout << "Enter info about engineer: " << endl;
  98.             cout << "\tfield: ";
  99.             cin >> field;
  100.             cout << "\tlevel: ";
  101.             cin >> level;
  102.             cout << endl;
  103.            
  104.             return;
  105.         }
  106.        
  107.         void getEngineer() {
  108.             cout << "Info about engineer: " << endl;
  109.             cout << "\tfield: " << field << endl;
  110.             cout << "\tlevel: " << level << endl << endl;
  111.            
  112.             return;
  113.         }  
  114. };
  115.  
  116. int main() {
  117.    
  118.     Engineer a("Mike", 36, 2300, 10, "mechanic", 3); //констуктор похідного класу для ініціалізації похідного і базових класів
  119.    
  120.     cout << "===Info about engineer A===" << endl;
  121.        
  122.     a.getEngineer(); //функція похідного класу
  123.     a.getServant(); //функція базового класу
  124.     a.getEmployee(); //функція базового класу
  125.     a.getPerson(); //функція базового класу
  126.    
  127.     Engineer b;
  128.    
  129.     cout << "===Enter info about engineer B===" << endl;
  130.    
  131.     b.setPerson(); //функція базового класу
  132.     b.setEmployee(); //функція базового класу
  133.     b.setServant(); //функція базового класу
  134.     b.setEngineer(); //функція похідного класу
  135.    
  136.     cout << "===Info about engineer B===" << endl;
  137.    
  138.     b.getEngineer(); //функція похідного класу
  139.     b.getServant(); //функція базового класу
  140.     b.getEmployee(); //функція базового класу
  141.     b.getPerson(); //функція базового класу
  142.    
  143.     return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement