Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Person
- {
- protected:
- string birthdate;
- string pol;
- public:
- string fio;
- Person* next;
- Person(const string name = "Unknown", const string date = "Unknown",
- const string sex = "Unknown", Person* n = NULL)
- {
- fio = name;
- birthdate = date;
- pol = sex;
- next = n;
- }
- void SetPersonInfo(string name, string date, string sex)
- {
- fio = name;
- birthdate = date;
- pol = sex;
- }
- virtual void PersonInfo(void) //вывод информации, переопределяется в производных классах
- {
- cout << "-----" << endl;
- cout << "Name: " << fio << endl;
- cout << "Date of birth: " << birthdate << endl;
- cout << "Sex: " << pol << endl;
- }
- };
- class Employee : public Person
- {
- protected:
- string post; //должность
- public:
- Employee(const string name = "Unknown", const string date = "Unknown",
- const string sex = "Unknown", Person* n = NULL, string p = "Employee")
- {
- post = p;
- Person(name, date, sex, n);
- }
- void PersonInfo(void) //вывод информации
- {
- Person::PersonInfo();
- cout << "Post: " << post << endl;
- }
- };
- class Manager : public Employee
- {
- protected:
- string department; //отдел
- Person* employers; //указатель на список сотрудников
- public:
- Manager(const string dep = "Unknown", const string name = "Unknown",
- const string date = "Unknown", const string sex = "Unknown",
- Person* n = NULL, string p = "Manager", Person* emp = NULL)
- {
- Employee(name, date, sex, n);
- post = "Manager";
- department = dep;
- employers = emp;
- }
- void AddEmployee(Employee* emp)
- {
- emp->next = employers;
- employers = emp;
- }
- void PersonInfo(void) //вывод информации
- {
- Employee::PersonInfo();
- cout << "Department: " << department << endl;
- cout << "Subordinate employers: ";
- if (employers == NULL) cout << "no subordinates" << endl;
- else {
- Person* emp = employers;
- while (emp != NULL) {
- cout << endl << " - " << emp->fio;
- emp = emp->next;
- }
- cout << endl;
- }
- }
- };
- class Chief : public Employee
- {
- protected:
- string firm; //наименование фирмы
- Person* managers;
- public:
- Chief(const string f = "Unknown", const string name = "Unknown",
- const string date = "Unknown", const string sex = "Unknown",
- Person* n = NULL, string p = "Chief", Person* manag = NULL)
- {
- Employee(name, date, sex, n);
- post = "Chief";
- firm = f;
- managers = manag;
- }
- void AddManager(Manager* man)
- {
- man->next = managers;
- managers = man;
- }
- void PersonInfo(void) //вывод информации
- {
- Employee::PersonInfo();
- cout << "Firm: " << firm << endl;
- cout << "Subordinate managers: ";
- if (managers == NULL) cout << "no subordinates" << endl;
- else {
- Person* man = managers;
- while (man != NULL) {
- cout << endl << " - " << man->fio;
- man = man->next;
- }
- cout << endl;
- }
- }
- };
- int main()
- {
- setlocale(0, "");
- Chief* ch = new Chief("Рога и копыта");
- ch->SetPersonInfo("Остап Бендер", "12.12.1212", "м");
- Manager* man1 = new Manager("Рога");
- man1->SetPersonInfo("Шура", "01.01.0101", "м");
- Manager* man2 = new Manager("Копыта");
- man2->SetPersonInfo("Паниковский", "10.10.1010", "м");
- Employee* emp1 = new Employee();
- emp1->SetPersonInfo("Козлов", "15.15.1515", "м");
- Employee* emp2 = new Employee();
- emp2->SetPersonInfo("Колбич", "01.02.3040", "м");
- Employee* emp3 = new Employee();
- emp3->SetPersonInfo("Ластова", "25.12.1512", "ж");
- Employee* emp4 = new Employee();
- emp4->SetPersonInfo("Луп", "25.08.1512", "ж");
- Employee* emp5 = new Employee();
- emp5->SetPersonInfo("Зар", "14.12.1412", "м");
- Employee* emp6 = new Employee();
- emp6->SetPersonInfo("Нортов", "12.02.1232", "м");
- ch->AddManager(man1);
- ch->AddManager(man2);
- man1->AddEmployee(emp1);
- man1->AddEmployee(emp2);
- man1->AddEmployee(emp3);
- man2->AddEmployee(emp4);
- man2->AddEmployee(emp5);
- man2->AddEmployee(emp6);
- ch->PersonInfo();
- man1->PersonInfo();
- man2->PersonInfo();
- emp1->PersonInfo();
- emp2->PersonInfo();
- emp3->PersonInfo();
- emp4->PersonInfo();
- emp5->PersonInfo();
- emp6->PersonInfo();
- delete(ch);
- delete(man1);
- delete(man2);
- delete(emp1);
- delete(emp2);
- delete(emp3);
- delete(emp4);
- delete(emp5);
- delete(emp6);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment