Advertisement
35657

Untitled

May 11th, 2024
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // Человек
  9. class Person {
  10. public:
  11.     Person() {
  12.         cout << "Конструткор класса Person" << endl;
  13.     };
  14.  
  15.     string GetName() const {
  16.         return name_;
  17.     }
  18.     int GetAge() const {
  19.         return age_;
  20.     }
  21.     string GetGender() const {
  22.         return gender_;
  23.     }
  24.    
  25.     ~Person() {
  26.         cout << "Деструктор класса Person" << endl;
  27.     };
  28.  
  29. private:
  30.     string name_;
  31.     string gender_;
  32.     int age_;
  33. };
  34.  
  35.  
  36. // Рабочий. Владеет несколькими специальностями
  37. class Worker : public Person {
  38. public:
  39.     Worker() {
  40.         cout << "Конструткор класса Worker" << endl;
  41.     };
  42.  
  43.     void AddSpeciality(string speciality) {
  44.         specialties_.insert(speciality);
  45.     }
  46.     bool HasSpeciality(string speciality) const {
  47.         return specialties_.count(speciality);
  48.     }
  49.  
  50.     ~Worker() {
  51.         cout << "Деструктор класса Worker" << endl;
  52.     };
  53.  
  54. private:
  55.     set<string> specialties_;
  56. };
  57.  
  58. // Маляр
  59. class Painter : public Worker {
  60. public:
  61.     Painter() {
  62.         cout << "Конструктор класса Painter" << endl;
  63.     };
  64.  
  65.     void Paint() {
  66.         cout << "Крашу стену" << endl;
  67.     }
  68.  
  69.  
  70.     ~Painter() {
  71.         cout << "Деструктор класса Painter" << endl;
  72.     };
  73. };
  74.  
  75. int main() {
  76.     setlocale(LC_ALL, "ru");
  77.  
  78.     //Person ps;
  79.  
  80.     //Worker wr;
  81.  
  82.     Painter pr;
  83.    
  84.     cout << endl << endl;
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement