Advertisement
Vladislav_Bezruk

lab 9 task 1

Oct 12th, 2021 (edited)
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 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 Employee {
  88.     string field;
  89.     int level;
  90.  
  91. public:
  92.     Engineer() {}
  93.  
  94.     Engineer(string n, int a, int s, string f, int l) : Employee(n, a, s), 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, "mechanic", 3); //констуктор похідного класу для ініціалізації похідного і базових класів
  119.  
  120.     cout << "===Info about engineer===" << endl;
  121.  
  122.     a.getEngineer(); //клас Engineer
  123.     a.getEmployee(); //клас Employee
  124.     a.getPerson(); //клас Person
  125.  
  126.     Servant b("Steve", 45, 3000, 20);
  127.  
  128.     cout << "===Info about servant===" << endl; //констуктор похідного класу для ініціалізації похідного і базових класів
  129.  
  130.     b.getServant(); //клас Servant
  131.     b.getEmployee(); //клас Employee
  132.     b.getPerson(); //клас Person
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement