Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- class Person
- {
- protected:
- char fio[100];
- char date_of_birth[12];
- char pol[5];
- Person* next;
- Person* head; //указатель на начало списка
- void AddToList(Person* person) {
- if (!head) {
- head = person;
- } else {
- Person* temp = head;
- while (temp->next) temp = temp->next;
- temp->next = person;
- }
- }
- public:
- void SetPersonInfo(const char *f, const char *d, const char *p)
- {
- //заносим данные в объект
- strcpy(fio, f);
- strcpy(date_of_birth, d);
- strcpy(pol, p);
- }
- void PersonInfo()
- {
- std::cout << "I'm:" << endl;
- printInfo();
- std::cout << "My men:" << endl;
- Person *temp = head;
- while (temp != nullptr) {
- temp->printInfo();
- temp = temp->next;
- }
- cout << endl;
- }
- virtual void printInfo() {
- cout << fio << endl;
- cout << date_of_birth << endl;
- cout << pol << endl;
- }
- Person():head(nullptr){}
- ~Person()
- {
- Person *temp = head;
- while (temp != nullptr) {
- Person* person = temp;
- temp = temp->next;
- delete person;
- }
- }
- };
- class Employee : public Person
- {
- protected:
- char position[30];
- };
- class Manager : public Employee
- {
- protected:
- char name_of_department[30];
- Person* employers;
- public:
- Manager(const char nOd[])
- {
- strcpy(name_of_department, nOd);
- }
- void addEmployee(Person* employee) {
- AddToList(employee);
- if (!employers) employers = head;
- }
- void printInfo() override {
- Person::printInfo();
- std::cout << name_of_department << endl;
- }
- };
- class Chief : public Employee
- {
- protected:
- char name_of_company[40];
- Person* managers;
- public:
- Chief(const char nOc[]):managers(nullptr)
- {
- strcpy(name_of_company, nOc);
- }
- void addManager(Manager* manager) {
- AddToList(manager);
- if (!managers) managers = head;
- }
- void printInfo() override {
- Person::printInfo();
- std::cout << name_of_company << endl;
- }
- };
- int main()
- {
- Chief* ch = new Chief("Horns and Hooves");
- ch->SetPersonInfo("Ostap Bender", "12.12.1212", "m");
- Manager* m1 = new Manager("Horns");
- m1->SetPersonInfo("Shura", "01.01.0101", "m");
- Manager* m2 = new Manager("Hooves");
- m2->SetPersonInfo("Panikovsky", "10.10.1010", "m");
- ch->addManager(m1);
- ch->addManager(m2);
- Person* person = new Person();
- person->SetPersonInfo("some_Person", "s", "1");
- m1->addEmployee(person);
- m1->PersonInfo();
- ch->PersonInfo();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement