Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Person {
- protected:
- string name;
- int age;
- public:
- Person() {}
- Person(string n, int a) : name(n), age(a) {}
- void setPerson() {
- cout << "Enter info about person: " << endl;
- cout << "\tname: ";
- cin >> name;
- cout << "\tage: ";
- cin >> age;
- cout << endl;
- return;
- }
- void getPerson() {
- cout << "Info about person: " << endl;
- cout << "\tname: " << name << endl;
- cout << "\tage: " << age << endl << endl;
- return;
- }
- };
- class Employee : public Person {
- protected:
- int salary;
- public:
- Employee() {}
- Employee(string n, int a, int s) : Person(n, a), salary(s) {}
- void setEmployee() {
- cout << "Enter info about employee: " << endl;
- cout << "\tsalary: ";
- cin >> salary;
- cout << endl;
- return;
- }
- void getEmployee() {
- cout << "Info about employee: " << endl;
- cout << "\tsalary: " << salary << endl << endl;
- return;
- }
- };
- class Servant : public Employee {
- protected:
- int experience;
- public:
- Servant() {}
- Servant(string n, int a, int s, int e) : Employee(n, a, s), experience(e) {}
- void setServant() {
- cout << "Enter info about servant: " << endl;
- cout << "\texperience: ";
- cin >> experience;
- cout << endl;
- return;
- }
- void getServant() {
- cout << "Info about servant: " << endl;
- cout << "\texperience: " << experience << endl << endl;
- return;
- }
- };
- class Engineer : public Servant {
- string field;
- int level;
- public:
- Engineer() {}
- Engineer(string n, int a, int s, int e, string f, int l) : Servant(n, a, s, e), field(f), level(l) {}
- void setEngineer() {
- cout << "Enter info about engineer: " << endl;
- cout << "\tfield: ";
- cin >> field;
- cout << "\tlevel: ";
- cin >> level;
- cout << endl;
- return;
- }
- void getEngineer() {
- cout << "Info about engineer: " << endl;
- cout << "\tfield: " << field << endl;
- cout << "\tlevel: " << level << endl << endl;
- return;
- }
- };
- int main() {
- Engineer a("Mike", 36, 2300, 10, "mechanic", 3); //констуктор похідного класу для ініціалізації похідного і базових класів
- cout << "===Info about engineer A===" << endl;
- a.getEngineer(); //функція похідного класу
- a.getServant(); //функція базового класу
- a.getEmployee(); //функція базового класу
- a.getPerson(); //функція базового класу
- Engineer b;
- cout << "===Enter info about engineer B===" << endl;
- b.setPerson(); //функція базового класу
- b.setEmployee(); //функція базового класу
- b.setServant(); //функція базового класу
- b.setEngineer(); //функція похідного класу
- cout << "===Info about engineer B===" << endl;
- b.getEngineer(); //функція похідного класу
- b.getServant(); //функція базового класу
- b.getEmployee(); //функція базового класу
- b.getPerson(); //функція базового класу
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement