palenda21

5laboop

Dec 9th, 2020 (edited)
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Person
  7. {
  8. protected:
  9. string birthdate;
  10.   string pol;
  11. public:
  12.   string fio;
  13.   Person* next;
  14.   Person(const string name = "Unknown", const string date = "Unknown",
  15.     const string sex = "Unknown", Person* n = NULL)
  16.   {
  17.     fio = name;
  18.     birthdate = date;
  19.     pol = sex;
  20.     next = n;
  21.   }
  22.   void SetPersonInfo(string name, string date, string sex)
  23.   {
  24.     fio = name;
  25.     birthdate = date;
  26.     pol = sex;
  27.   }
  28.   virtual void PersonInfo(void) //вывод информации, переопределяется в производных классах
  29.   {
  30.     cout << "-----" << endl;
  31.     cout << "Name: " << fio << endl;
  32.     cout << "Date of birth: " << birthdate << endl;
  33.     cout << "Sex: " << pol << endl;
  34.   }
  35. };
  36.  
  37. class Employee : public Person
  38. {
  39. protected:
  40.   string post; //должность
  41. public:
  42.   Employee(const string name = "Unknown", const string date = "Unknown",
  43.     const string sex = "Unknown", Person* n = NULL, string p = "Employee")
  44.   {
  45.     post = p;
  46.     Person(name, date, sex, n);
  47.   }
  48.   void PersonInfo(void) //вывод информации
  49.   {
  50.     Person::PersonInfo();
  51.     cout << "Post: " << post << endl;
  52.   }
  53. };
  54.  
  55. class Manager : public Employee
  56. {
  57. protected:
  58.   string department; //отдел
  59.   Person* employers; //указатель на список сотрудников
  60. public:
  61.   Manager(const string dep = "Unknown", const string name = "Unknown",
  62.     const string date = "Unknown", const string sex = "Unknown",
  63.     Person* n = NULL, string p = "Manager", Person* emp = NULL)
  64.   {
  65.     Employee(name, date, sex, n);
  66.     post = "Manager";
  67.     department = dep;
  68.     employers = emp;
  69.   }
  70.   void AddEmployee(Employee* emp)
  71.   {
  72.     emp->next = employers;
  73.     employers = emp;
  74.   }
  75.   void PersonInfo(void) //вывод информации
  76.   {
  77.     Employee::PersonInfo();
  78.     cout << "Department: " << department << endl;
  79.     cout << "Subordinate employers: ";
  80.     if (employers == NULL) cout << "no subordinates" << endl;
  81.     else {
  82.       Person* emp = employers;
  83.       while (emp != NULL) {
  84.         cout << endl << " - " << emp->fio;
  85.         emp = emp->next;
  86.       }
  87.       cout << endl;
  88.     }
  89.   }
  90. };
  91.  
  92. class Chief : public Employee
  93. {
  94. protected:
  95.   string firm; //наименование фирмы
  96.   Person* managers;
  97. public:
  98.   Chief(const string f = "Unknown", const string name = "Unknown",
  99.     const string date = "Unknown", const string sex = "Unknown",
  100.     Person* n = NULL, string p = "Chief", Person* manag = NULL)
  101.   {
  102.     Employee(name, date, sex, n);
  103.     post = "Chief";
  104.     firm = f;
  105.     managers = manag;
  106.   }
  107.   void AddManager(Manager* man)
  108.   {
  109.     man->next = managers;
  110.     managers = man;
  111.   }
  112.   void PersonInfo(void) //вывод информации
  113.   {
  114.     Employee::PersonInfo();
  115.     cout << "Firm: " << firm << endl;
  116.     cout << "Subordinate managers: ";
  117.     if (managers == NULL) cout << "no subordinates" << endl;
  118.     else {
  119.       Person* man = managers;
  120.       while (man != NULL) {
  121.         cout << endl << " - " << man->fio;
  122.         man = man->next;
  123.       }
  124.       cout << endl;
  125.     }
  126.   }
  127.  
  128. };
  129.  
  130. int main()
  131. {
  132.   setlocale(0, "");
  133.   Chief* ch = new Chief("Рога и копыта");
  134.   ch->SetPersonInfo("Остап Бендер", "12.12.1212", "м");
  135.   Manager* man1 = new Manager("Рога");
  136.   man1->SetPersonInfo("Шура", "01.01.0101", "м");
  137.   Manager* man2 = new Manager("Копыта");
  138.   man2->SetPersonInfo("Паниковский", "10.10.1010", "м");
  139.   Employee* emp1 = new Employee();
  140.   emp1->SetPersonInfo("Козлов", "15.15.1515", "м");
  141.   Employee* emp2 = new Employee();
  142.   emp2->SetPersonInfo("Колбич", "01.02.3040", "м");
  143.   Employee* emp3 = new Employee();
  144.   emp3->SetPersonInfo("Ластова", "25.12.1512", "ж");
  145.   Employee* emp4 = new Employee();
  146.   emp4->SetPersonInfo("Луп", "25.08.1512", "ж");
  147.   Employee* emp5 = new Employee();
  148.   emp5->SetPersonInfo("Зар", "14.12.1412", "м");
  149.   Employee* emp6 = new Employee();
  150.   emp6->SetPersonInfo("Нортов", "12.02.1232", "м");
  151.   ch->AddManager(man1);
  152.   ch->AddManager(man2);
  153.   man1->AddEmployee(emp1);
  154.   man1->AddEmployee(emp2);
  155.   man1->AddEmployee(emp3);
  156.   man2->AddEmployee(emp4);
  157.   man2->AddEmployee(emp5);
  158.   man2->AddEmployee(emp6);
  159.   ch->PersonInfo();
  160.   man1->PersonInfo();
  161.   man2->PersonInfo();
  162.   emp1->PersonInfo();
  163.   emp2->PersonInfo();
  164.   emp3->PersonInfo();
  165.   emp4->PersonInfo();
  166.   emp5->PersonInfo();
  167.   emp6->PersonInfo();
  168.   delete(ch);
  169.   delete(man1);
  170.   delete(man2);
  171.   delete(emp1);
  172.   delete(emp2);
  173.   delete(emp3);
  174.   delete(emp4);
  175.   delete(emp5);
  176.   delete(emp6);
  177.   system("pause");
  178.   return 0;
  179. }
  180.  
  181.  
Add Comment
Please, Sign In to add comment