35657

Untitled

May 14th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1.  
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9.  
  10. // Рабочий
  11. class Worker {
  12. public:
  13.  
  14.     Worker() {
  15.         cout << "Конструктор рабочего" << endl;
  16.     }
  17.  
  18.     void SetSpeciality(string speciality) {
  19.         speciality_ = speciality;
  20.     }
  21.     string GetSpeciality() const {
  22.         return speciality_;
  23.     }
  24.  
  25. private:
  26.     string speciality_;
  27. };
  28.  
  29.  
  30. // Студент
  31. class Student {
  32. public:
  33.  
  34.     Student() {
  35.         cout << "Конструктор студента" << endl;
  36.     }
  37.  
  38.     void SetFaculty(string faculty) {
  39.         faculty_ = faculty;
  40.     }
  41.     string GetFaculty() const {
  42.         return faculty_;
  43.     }
  44.  
  45. private:
  46.     string faculty_;
  47. };
  48.  
  49.  
  50. //
  51. class ExternalStudent : public Worker, public Student  {
  52.  
  53. public:
  54.     ExternalStudent() { // фактически компилятор допишет перед фигурными скобками Worker(), Builder()
  55.         cout << "Конструктор заочника" << endl;
  56.     }
  57. };
  58.  
  59.  
  60. int main() {
  61.     setlocale(LC_ALL, "ru");
  62.  
  63.     ExternalStudent ex;
  64.  
  65.     ex.SetSpeciality("Builder");
  66.     ex.SetFaculty("Programming");
  67.  
  68.     cout << ex.GetSpeciality() << " " << ex.GetFaculty() << endl;
  69.  
  70. }
Add Comment
Please, Sign In to add comment