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 Employee {
- string field;
- int level;
- public:
- Engineer() {}
- Engineer(string n, int a, int s, string f, int l) : Employee(n, a, s), 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, "mechanic", 3); //констуктор похідного класу для ініціалізації похідного і базових класів
- cout << "===Info about engineer===" << endl;
- a.getEngineer(); //клас Engineer
- a.getEmployee(); //клас Employee
- a.getPerson(); //клас Person
- Servant b("Steve", 45, 3000, 20);
- cout << "===Info about servant===" << endl; //констуктор похідного класу для ініціалізації похідного і базових класів
- b.getServant(); //клас Servant
- b.getEmployee(); //клас Employee
- b.getPerson(); //клас Person
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement