Advertisement
35657

Untitled

Jul 14th, 2023
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1.  
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // Человек
  9. class Person {
  10. public:
  11.  
  12.     void SetName(string name) {
  13.         name_ = name;
  14.     }
  15.  
  16.     void SetGender(string gender) {
  17.         gender_ = gender;
  18.     }
  19.  
  20.     void SetAge(int age) {
  21.         age_ = age;
  22.     }
  23.  
  24.     string GetName() const {
  25.         return name_;
  26.     }
  27.     int GetAge() const {
  28.         return age_;
  29.     }
  30.     string GetGender() const {
  31.         return gender_;
  32.     }
  33.  
  34.     string name_;
  35.     string gender_;
  36.     int age_;
  37. };
  38.  
  39. // Рабочий
  40. class Worker : public virtual Person {
  41. public:
  42.  
  43.     void SetSpeciality(string speciality) {
  44.         speciality_ = speciality;
  45.     }
  46.     string GetSpeciality() const {
  47.         return speciality_;
  48.     }
  49.  
  50.     void Speak() {
  51.         cout << "Привет, я рабочий" << endl;
  52.     }
  53.  
  54. private:
  55.     string speciality_;
  56. };
  57.  
  58.  
  59. // Студент
  60. class Student : public virtual Person {
  61. public:
  62.  
  63.     void SetFaculty(string faculty) {
  64.         faculty_ = faculty;
  65.     }
  66.     string GetFaculty() const {
  67.         return faculty_;
  68.     }
  69.  
  70.     void Speak() {
  71.         cout << "Привет, я студент" << endl;
  72.     }
  73.  
  74. private:
  75.     string faculty_;
  76. };
  77.  
  78.  
  79. //
  80. class ExternalStudent : public Worker, public Student  {
  81.  
  82. };
  83.  
  84.  
  85. int main() {
  86.     setlocale(LC_ALL, "ru");
  87.  
  88.     ExternalStudent ex;
  89.  
  90.     ex.SetSpeciality("Builder");
  91.     ex.SetFaculty("Programming");
  92.  
  93.     cout << ex.GetSpeciality() << " " << ex.GetFaculty() << endl;
  94.  
  95.     ex.SetName("Иван"); // теперь это работает
  96.     cout << ex.GetName() << endl;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement