Advertisement
35657

Untitled

May 14th, 2024
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 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.     ~Worker() {
  26.         cout << "Деструктор рабочего" << endl;
  27.     }
  28.  
  29. private:
  30.     string speciality_;
  31. };
  32.  
  33.  
  34. // Студент
  35. class Student {
  36. public:
  37.  
  38.     Student() {
  39.         cout << "Конструктор студента" << endl;
  40.     }
  41.  
  42.     void SetFaculty(string faculty) {
  43.         faculty_ = faculty;
  44.     }
  45.     string GetFaculty() const {
  46.         return faculty_;
  47.     }
  48.  
  49.     ~Student() {
  50.         cout << "Деструктор студента" << endl;
  51.     }
  52.  
  53. private:
  54.     string faculty_;
  55. };
  56.  
  57.  
  58. //
  59. class ExternalStudent : public Worker, public Student  {
  60.  
  61. public:
  62.     ExternalStudent() {
  63.         cout << "Конструктор заочника" << endl;
  64.     }
  65.  
  66.     ~ExternalStudent() {
  67.         cout << "Деструктор заочника" << endl;
  68.     }
  69. };
  70.  
  71.  
  72. int main() {
  73.     setlocale(LC_ALL, "ru");
  74.  
  75.     ExternalStudent ex;
  76.  
  77.     ex.SetSpeciality("Builder");
  78.     ex.SetFaculty("Programming");
  79.  
  80.     cout << endl << endl;
  81.  
  82.     cout << ex.GetSpeciality() << " " << ex.GetFaculty() << endl;
  83.  
  84.     cout << endl << endl;
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement