Advertisement
35657

Untitled

May 11th, 2024
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 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.  
  26. private:
  27.     string name_;
  28.     string gender_;
  29.     int age_;
  30. };
  31.  
  32.  
  33. // Рабочий. Владеет несколькими специальностями
  34. class Worker : public Person {
  35. public:
  36.     Worker() {
  37.         cout << "Конструткор класса Worker" << endl;
  38.     };
  39.  
  40.     void AddSpeciality(string speciality) {
  41.         specialties_.insert(speciality);
  42.     }
  43.     bool HasSpeciality(string speciality) const {
  44.         return specialties_.count(speciality);
  45.     }
  46.  
  47. private:
  48.     set<string> specialties_;
  49. };
  50.  
  51. // Маляр
  52. class Painter : public Worker {
  53. public:
  54.     Painter() {
  55.         cout << "Конструктор класса Painter";
  56.     };
  57.  
  58.     void Paint() {
  59.         cout << "Крашу стену" << endl;
  60.     }
  61.  
  62. };
  63.  
  64. int main() {
  65.     setlocale(LC_ALL, "ru");
  66.  
  67.     Painter pr;
  68.    
  69.     //Worker wr;
  70.    
  71.      //Person ps;
  72.    
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement