Advertisement
35657

Untitled

May 16th, 2024
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. using namespace std;
  5.  
  6. class worker {
  7.  
  8. public:
  9.  
  10.     worker(string name, int salary, int id) : name_(name), salary_(salary), id_(id) {}
  11.  
  12.     void set_name(const string& name) {
  13.         name_ = name;
  14.     }
  15.  
  16.     string get_name() {
  17.         return name_;
  18.     }
  19.  
  20.     void set_salary(int salary) {
  21.         salary_ = salary;
  22.     }
  23.  
  24.     int get_salary() {
  25.         return salary_;
  26.     }
  27.  
  28.     void set_id(int id) {
  29.         id_ = id;
  30.     }
  31.  
  32.     int get_id() {
  33.         return id_;
  34.     }
  35.  
  36.     virtual void work() = 0;
  37.  
  38. private:
  39.     string name_;
  40.     int salary_;
  41.     int id_;
  42. };
  43.  
  44. class programmer : public worker {
  45.  
  46. public:
  47.     programmer(string name, int salary, int id) : worker(name, salary, id) {}
  48.  
  49.     void add_project(string project_name) {
  50.         projects_.insert(project_name);
  51.     }
  52.  
  53.     void del_project(string project_name) {
  54.         projects_.erase(project_name);
  55.     }
  56.  
  57.     int get_project_number() {
  58.         return projects_.size();
  59.     }
  60.  
  61.     void work() override {
  62.         cout << "Я пишу код" << endl;
  63.     }
  64.  
  65. private:
  66.     set<string> projects_;
  67. };
  68.  
  69. class manager : public worker {
  70.  
  71. public:
  72.     manager(string name, int salary, int id, string department_name, int employees_number) : worker(name, salary, id), department_name_(department_name), employees_number_(employees_number) {}
  73.  
  74.     int get_employees_number() {
  75.         return employees_number_;
  76.     }
  77.  
  78.     void set_department_name(string name) {
  79.         department_name_ = name;
  80.     }
  81.  
  82.     string get_department_name() {
  83.         return department_name_;
  84.     }
  85.  
  86.     void work() override {
  87.         cout << "Я руковожу" << endl;
  88.     }
  89.  
  90. private:
  91.     string department_name_;
  92.     int employees_number_;
  93. };
  94.  
  95. int main() {
  96.     setlocale(LC_ALL, "ru");
  97.  
  98.     programmer pr("Иван", 1000, 12356733);
  99.    
  100.     manager mn("Оля", 2000, 12356741, "Отдел разработки", 10);
  101.  
  102.     pr.add_project("Калькулятор");
  103.  
  104.     cout << pr.get_project_number() << endl;
  105.  
  106.     cout << mn.get_department_name() << endl;
  107.  
  108.     mn.work();
  109.  
  110.     pr.work();
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement