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 _name, int _age) : name(_name), age(_age) {}
- void get() {
- cout << "name: " << name << endl;
- cout << "age: " << age << endl;
- }
- void set() {
- cout << "name: ";
- cin >> name;
- cout << "age: ";
- cin >> age;
- }
- };
- class Student : public Person {
- protected:
- string university;
- string specialty;
- public:
- Student() {}
- Student(string _name, int _age, string _university, string _specialty) : Person(_name, _age),
- university(_university), specialty(_specialty) {}
- void get() {
- Person::get();
- cout << "university: " << university << endl;
- cout << "specialty: " << specialty << endl;
- }
- void set() {
- Person::set();
- cout << "university: ";
- cin >> university;
- cout << "specialty: ";
- cin >> specialty;
- }
- };
- class Teacher : public Student {
- protected:
- int experience;
- float salary;
- public:
- Teacher() {}
- Teacher(string _name, int _age, string _university,
- string _specialty, int _experience, float _salary) : Student(_name, _age, _university, _specialty),
- experience(_experience), salary(_salary) {}
- void get() {
- Student::get();
- cout << "experience: " << experience << endl;
- cout << "salary: " << salary << endl;
- }
- void set() {
- Student::set();
- cout << "experience: ";
- cin >> experience;
- cout << "salary: ";
- cin >> salary;
- }
- };
- class DepartmentChair : public Teacher {
- string department;
- public:
- DepartmentChair() {}
- DepartmentChair(string _name, int _age, string _university,
- string _specialty, int _experience, float _salary, string _department) :
- Teacher(_name, _age, _university, _specialty, _experience, _salary),
- department(_department) {}
- void get() {
- Teacher::get();
- cout << "department: " << department << endl;
- }
- void set() {
- Teacher::set();
- cout << "department: ";
- cin >> department;
- }
- };
- int main() {
- Student student;
- Teacher teacher;
- DepartmentChair departmentChair;
- cout << "Enter info about student:" << endl;
- student.set(); //class Student
- cout << endl << "Info about student:" << endl;
- student.get(); //class Student
- cout << endl << "Enter info about teacher:" << endl;
- teacher.set(); //class Teacher
- cout << endl << "Info about teacher:" << endl;
- teacher.get(); //class Teacher
- cout << endl << "Enter info about department chair:" << endl;
- departmentChair.set(); //class DepartmentChair
- cout << endl << "Info about department chair:" << endl;
- departmentChair.get(); //class DepartmentChair
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement