Advertisement
wcobalt

Untitled

Oct 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. class Person
  8. {
  9. protected:
  10.     char fio[100];
  11.     char date_of_birth[12];
  12.     char pol[5];
  13.     Person* next;
  14.     Person* head; //указатель на начало списка
  15.  
  16.     void AddToList(Person* person) {
  17.         if (!head) {
  18.             head = person;
  19.         }  else {
  20.             Person* temp = head;
  21.  
  22.             while (temp->next) temp = temp->next;
  23.  
  24.             temp->next = person;
  25.         }
  26.     }
  27. public:
  28.     void SetPersonInfo(const char *f, const char *d, const char *p)
  29.     {
  30.         //заносим данные в объект
  31.         strcpy(fio, f);
  32.         strcpy(date_of_birth, d);
  33.         strcpy(pol, p);
  34.     }
  35.  
  36.     void PersonInfo()
  37.     {
  38.         Person *temp = head;
  39.  
  40.         while (temp != nullptr) {
  41.             temp->printInfo();
  42.             temp = temp->next;
  43.         }
  44.  
  45.         cout << endl;
  46.     }
  47.  
  48.     virtual void printInfo() {
  49.         cout << fio << endl;
  50.         cout << date_of_birth << endl;
  51.         cout << pol << endl;
  52.     }
  53.  
  54.     Person():head(nullptr){}
  55.  
  56.     ~Person()
  57.     {
  58.         Person *temp = head;
  59.  
  60.         while (temp != nullptr) {
  61.             Person* person = temp;
  62.  
  63.             temp = temp->next;
  64.  
  65.             delete person;
  66.         }
  67.     }
  68. };
  69.  
  70. class Employee : public Person
  71. {
  72. protected:
  73.     char position[30];
  74. };
  75.  
  76. class Manager : public Employee
  77. {
  78. protected:
  79.     char name_of_department[30];
  80.     Person* employers;
  81. public:
  82.     Manager(const char nOd[])
  83.     {
  84.         strcpy(name_of_department, nOd);
  85.     }
  86.  
  87.     void addEmployee(Person* employee) {
  88.         AddToList(employee);
  89.  
  90.         if (!employers) employers = head;
  91.     }
  92.  
  93.     void printInfo() override {
  94.         Person::printInfo();
  95.  
  96.         std::cout << name_of_department << endl;
  97.     }
  98. };
  99.  
  100. class Chief : public Employee
  101. {
  102. protected:
  103.     char name_of_company[40];
  104.     Person* managers;
  105. public:
  106.     Chief(const char nOc[]):managers(nullptr)
  107.     {
  108.         strcpy(name_of_company, nOc);
  109.     }
  110.  
  111.     void addManager(Manager* manager) {
  112.         AddToList(manager);
  113.  
  114.         if (!managers) managers = head;
  115.     }
  116.  
  117.     void printInfo() override {
  118.         Person::printInfo();
  119.  
  120.         std::cout << name_of_company << endl;
  121.     }
  122. };
  123.  
  124.  
  125. int main()
  126. {
  127.     Chief* ch = new Chief("Horns and Hooves");
  128.     ch->SetPersonInfo("Ostap Bender", "12.12.1212", "m");
  129.     Manager* m1 = new Manager("Horns");
  130.     m1->SetPersonInfo("Shura", "01.01.0101", "m");
  131.     Manager* m2 = new Manager("Hooves");
  132.     m2->SetPersonInfo("Panikovsky", "10.10.1010", "m");
  133.     ch->addManager(m1);
  134.     ch->addManager(m2);
  135.  
  136.     Person* person = new Person();
  137.     person->SetPersonInfo("some_Person", "s", "1");
  138.     m1->addEmployee(person);
  139.  
  140.     m1->PersonInfo();
  141.  
  142.     ch->PersonInfo();
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement