35657

Untitled

Jul 21st, 2023
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. // Служащий
  9. class Employer {
  10. public:
  11.  
  12.     string GetName() const {
  13.         return name_;
  14.     }
  15.     int GetAge() const {
  16.         return age_;
  17.     }
  18.     string GetGender() const {
  19.         return gender_;
  20.     }
  21.  
  22.     virtual void Print() {
  23.         cout << "Я служащий" << endl;
  24.     }
  25.  
  26.     void SetName(string name) {
  27.         name_ = name;
  28.     }
  29.  
  30.     void SetAge(int age) {
  31.         age_ = age;
  32.     }
  33.  
  34.     void SetGender(string gender) {
  35.         gender_ = gender;
  36.     }
  37.  
  38. protected:
  39.     string name_;
  40.     int age_;
  41.     string gender_;
  42. };
  43.  
  44. class President : public Employer {
  45. public:
  46.     void Print() {
  47.         cout << "Я президент " << endl;
  48.     }
  49. };
  50.  
  51. class Manager : public Employer {
  52. public:
  53.     void Print() {
  54.         cout << "Я менеджер" << endl;
  55.     }
  56. };
  57.  
  58. class Worker : public Employer {
  59. public:
  60.     void Print() {
  61.         cout << "Я рабочий" << endl;
  62.     }
  63. };
  64.  
  65. int main() {
  66.     setlocale(LC_ALL, "ru");
  67.  
  68.     President pr;
  69.     Manager mn;
  70.     Worker wk;
  71.  
  72.     vector<Employer*> employers;
  73.  
  74.     employers.push_back(&pr);
  75.     employers.push_back(&mn);
  76.     employers.push_back(&wk);
  77.  
  78.  
  79.     for (auto a : employers) {
  80.         a->Print();
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment