Advertisement
Marisichka

Untitled

Nov 6th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Person {
  6. protected:
  7.     string name;
  8.     int age;
  9.  
  10. public:
  11.     Person() {}
  12.  
  13.     Person(string _name, int _age) : name(_name), age(_age) {}
  14.  
  15.     void get() {
  16.         cout << "name: " << name << endl;
  17.         cout << "age: " << age << endl;
  18.     }
  19.  
  20.     void set() {
  21.         cout << "name: ";
  22.         cin >> name;
  23.         cout << "age: ";
  24.         cin >> age;
  25.     }
  26. };
  27.  
  28. class Student : public Person {
  29. protected:
  30.     string university;
  31.     string specialty;
  32.  
  33. public:
  34.     Student() {}
  35.  
  36.     Student(string _name, int _age, string _university, string _specialty) : Person(_name, _age),
  37.         university(_university), specialty(_specialty) {}
  38.  
  39.     void get() {
  40.         Person::get();
  41.         cout << "university: " << university << endl;
  42.         cout << "specialty: " << specialty << endl;
  43.     }
  44.  
  45.     void set() {
  46.         Person::set();
  47.         cout << "university: ";
  48.         cin >> university;
  49.         cout << "specialty: ";
  50.         cin >> specialty;
  51.     }
  52. };
  53.  
  54. class Teacher : public Student {
  55. protected:
  56.     int experience;
  57.     float salary;
  58.  
  59. public:
  60.     Teacher() {}
  61.  
  62.     Teacher(string _name, int _age, string _university,
  63.         string _specialty, int _experience, float _salary) : Student(_name, _age, _university, _specialty),
  64.         experience(_experience), salary(_salary) {}
  65.  
  66.     void get() {
  67.         Student::get();
  68.         cout << "experience: " << experience << endl;
  69.         cout << "salary: " << salary << endl;
  70.     }
  71.  
  72.     void set() {
  73.         Student::set();
  74.         cout << "experience: ";
  75.         cin >> experience;
  76.         cout << "salary: ";
  77.         cin >> salary;
  78.     }
  79. };
  80.  
  81. class DepartmentChair : public Teacher {
  82.     string department;
  83.  
  84. public:
  85.     DepartmentChair() {}
  86.  
  87.     DepartmentChair(string _name, int _age, string _university,
  88.         string _specialty, int _experience, float _salary, string _department) :
  89.         Teacher(_name, _age, _university, _specialty, _experience, _salary),
  90.         department(_department) {}
  91.  
  92.     void get() {
  93.         Teacher::get();
  94.         cout << "department: " << department << endl;
  95.     }
  96.  
  97.     void set() {
  98.         Teacher::set();
  99.         cout << "department: ";
  100.         cin >> department;
  101.     }
  102. };
  103.  
  104. int main() {
  105.  
  106.     Student student;
  107.     Teacher teacher;
  108.     DepartmentChair departmentChair;
  109.  
  110.     cout << "Enter info about student:" << endl;
  111.     student.set(); //class Student
  112.     cout << endl << "Info about student:" << endl;
  113.     student.get(); //class Student
  114.  
  115.     cout << endl << "Enter info about teacher:" << endl;
  116.     teacher.set(); //class Teacher
  117.     cout << endl << "Info about teacher:" << endl;
  118.     teacher.get(); //class Teacher
  119.  
  120.     cout << endl << "Enter info about department chair:" << endl;
  121.     departmentChair.set(); //class DepartmentChair
  122.     cout << endl << "Info about department chair:" << endl;
  123.     departmentChair.get(); //class DepartmentChair
  124.  
  125.     return 0;
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement