SHARE
TWEET

Untitled

wcobalt Oct 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         std::cout << "I'm:" << endl;
  39.        
  40.         printInfo();
  41.  
  42.         std::cout << "My men:" << endl;
  43.  
  44.         Person *temp = head;
  45.  
  46.         while (temp != nullptr) {
  47.             temp->printInfo();
  48.             temp = temp->next;
  49.         }
  50.  
  51.         cout << endl;
  52.     }
  53.  
  54.     virtual void printInfo() {
  55.         cout << fio << endl;
  56.         cout << date_of_birth << endl;
  57.         cout << pol << endl;
  58.     }
  59.  
  60.     Person():head(nullptr){}
  61.  
  62.     ~Person()
  63.     {
  64.         Person *temp = head;
  65.  
  66.         while (temp != nullptr) {
  67.             Person* person = temp;
  68.  
  69.             temp = temp->next;
  70.  
  71.             delete person;
  72.         }
  73.     }
  74. };
  75.  
  76. class Employee : public Person
  77. {
  78. protected:
  79.     char position[30];
  80. };
  81.  
  82. class Manager : public Employee
  83. {
  84. protected:
  85.     char name_of_department[30];
  86.     Person* employers;
  87. public:
  88.     Manager(const char nOd[])
  89.     {
  90.         strcpy(name_of_department, nOd);
  91.     }
  92.  
  93.     void addEmployee(Person* employee) {
  94.         AddToList(employee);
  95.  
  96.         if (!employers) employers = head;
  97.     }
  98.  
  99.     void printInfo() override {
  100.         Person::printInfo();
  101.  
  102.         std::cout << name_of_department << endl;
  103.     }
  104. };
  105.  
  106. class Chief : public Employee
  107. {
  108. protected:
  109.     char name_of_company[40];
  110.     Person* managers;
  111. public:
  112.     Chief(const char nOc[]):managers(nullptr)
  113.     {
  114.         strcpy(name_of_company, nOc);
  115.     }
  116.  
  117.     void addManager(Manager* manager) {
  118.         AddToList(manager);
  119.  
  120.         if (!managers) managers = head;
  121.     }
  122.  
  123.     void printInfo() override {
  124.         Person::printInfo();
  125.  
  126.         std::cout << name_of_company << endl;
  127.     }
  128. };
  129.  
  130.  
  131. int main()
  132. {
  133.     Chief* ch = new Chief("Horns and Hooves");
  134.     ch->SetPersonInfo("Ostap Bender", "12.12.1212", "m");
  135.     Manager* m1 = new Manager("Horns");
  136.     m1->SetPersonInfo("Shura", "01.01.0101", "m");
  137.     Manager* m2 = new Manager("Hooves");
  138.     m2->SetPersonInfo("Panikovsky", "10.10.1010", "m");
  139.     ch->addManager(m1);
  140.     ch->addManager(m2);
  141.  
  142.     Person* person = new Person();
  143.     person->SetPersonInfo("some_Person", "s", "1");
  144.     m1->addEmployee(person);
  145.  
  146.     m1->PersonInfo();
  147.  
  148.     ch->PersonInfo();
  149. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top