Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Person {
- protected:
- int age;
- string name;
- public:
- Person() {}
- Person(int _age, string _name) : age(_age), name(_name) {}
- void set() {
- cout << "age: "; cin >> age;
- cout << "name: "; cin >> name;
- }
- void get() {
- cout << "age: " << age << endl;
- cout << "name: " << name << endl;
- }
- };
- class Employee : public Person {
- protected:
- int salary;
- string area;
- public:
- Employee() {}
- Employee(int _age, string _name, int _salary, string _area) : Person(_age, _name), salary(_salary), area(_area) {}
- void set() {
- Person :: set(); //клас Person
- cout << "salary: "; cin >> salary;
- cout << "area: "; cin >> area;
- }
- void get() {
- Person :: get(); //клас Person
- cout << "salary: " << salary << endl;
- cout << "area: " << area << endl;
- }
- };
- class Engineer : public Employee {
- protected:
- int level;
- string type;
- public:
- Engineer() {}
- Engineer(int _age, string _name, int _salary, string _area, int _level, string _type) : Employee(_age, _name, _salary, _area), level(_level), type(_type) {}
- void set() {
- cout << "Enter info about engineer:" << endl;
- Employee :: set(); //клас Employee
- cout << "level: "; cin >> level;
- cout << "type: "; cin >> type;
- cout << endl;
- }
- void get() {
- cout << "Info about engineer:" << endl;
- Employee :: get(); //клас Employee
- cout << "level: " << level << endl;
- cout << "type: " << type << endl;
- cout << endl;
- }
- };
- class Servant : public Person {
- protected:
- int yearsService;
- public:
- Servant() {}
- Servant(int _age, string _name, int _yearsService) : Person(_age, _name), yearsService(_yearsService) {}
- void set() {
- cout << "Enter info about servant:" << endl;
- Person :: set(); //клас Person
- cout << "years of service: "; cin >> yearsService;
- cout << endl;
- }
- void get() {
- cout << "Info about servant:" << endl;
- Person :: get(); //клас Person
- cout << "years of service: " << yearsService << endl;
- cout << endl;
- }
- };
- int main() {
- Engineer engineer;
- engineer.set(); //клас Engineer
- engineer.get(); //клас Engineer
- Servant servant;
- servant.set(); //клас Servant
- servant.get(); //клас Servant
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement