Advertisement
35657

Untitled

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