Advertisement
Vladislav_Bezruk

Untitled

Oct 19th, 2021
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Person {
  6.     protected:
  7.         int age;
  8.         string name;
  9.        
  10.     public:
  11.         Person() {}
  12.        
  13.         Person(int _age, string _name) : age(_age), name(_name) {}
  14.        
  15.         void set() {
  16.             cout << "age: "; cin >> age;
  17.             cout << "name: "; cin >> name;
  18.         }
  19.        
  20.         void get() {
  21.             cout << "age: " << age << endl;
  22.             cout << "name: " << name << endl;
  23.         }
  24. };
  25.  
  26. class Employee : public Person {
  27.     protected:
  28.         int salary;
  29.         string area;
  30.        
  31.     public:
  32.         Employee() {}
  33.        
  34.         Employee(int _age, string _name, int _salary, string _area) : Person(_age, _name), salary(_salary), area(_area) {}
  35.        
  36.         void set() {
  37.             Person :: set(); //клас Person
  38.             cout << "salary: "; cin >> salary;
  39.             cout << "area: "; cin >> area;
  40.         }
  41.        
  42.         void get() {
  43.             Person :: get(); //клас Person
  44.             cout << "salary: " << salary << endl;  
  45.             cout << "area: " << area << endl;  
  46.         }
  47. };
  48.  
  49. class Engineer : public Employee {
  50.     protected:
  51.         int level;
  52.         string type;
  53.        
  54.     public:
  55.         Engineer() {}
  56.        
  57.         Engineer(int _age, string _name, int _salary, string _area, int _level, string _type) : Employee(_age, _name, _salary, _area), level(_level), type(_type) {}
  58.        
  59.         void set() {
  60.             cout << "Enter info about engineer:" << endl;
  61.             Employee :: set(); //клас Employee
  62.             cout << "level: "; cin >> level;
  63.             cout << "type: "; cin >> type;
  64.             cout << endl;
  65.         }
  66.        
  67.         void get() {
  68.             cout << "Info about engineer:" << endl;
  69.             Employee :: get(); //клас Employee
  70.             cout << "level: " << level << endl;
  71.             cout << "type: " << type << endl;  
  72.             cout << endl;
  73.         }
  74. };
  75.  
  76. class Servant : public Person {
  77.     protected:
  78.         int yearsService;
  79.        
  80.     public:
  81.         Servant() {}
  82.        
  83.         Servant(int _age, string _name, int _yearsService) : Person(_age, _name), yearsService(_yearsService) {}
  84.        
  85.         void set() {
  86.             cout << "Enter info about servant:" << endl;
  87.             Person :: set(); //клас Person
  88.             cout << "years of service: "; cin >> yearsService;
  89.             cout << endl;
  90.         }
  91.        
  92.         void get() {
  93.             cout << "Info about servant:" << endl;
  94.             Person :: get(); //клас Person
  95.             cout << "years of service: " << yearsService << endl;  
  96.             cout << endl;
  97.         }
  98. };
  99.  
  100. int main() {
  101.    
  102.     Engineer engineer;
  103.    
  104.     engineer.set(); //клас Engineer
  105.    
  106.     engineer.get(); //клас Engineer
  107.    
  108.     Servant servant;
  109.    
  110.     servant.set(); //клас Servant
  111.    
  112.     servant.get(); //клас Servant
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement