Advertisement
35657

Untitled

May 11th, 2024
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 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.     Person(string name) {
  16.         name_ = name;
  17.         cout << "Параметризованный конструткор класса Person" << endl;
  18.     };
  19.  
  20.     Person(string name, int age) {
  21.         name_ = name;
  22.         age_ = age;
  23.         cout << "другой параметризованный конструткор класса Person" << endl;
  24.     };
  25.  
  26.     string GetName() const {
  27.         return name_;
  28.     }
  29.     int GetAge() const {
  30.         return age_;
  31.     }
  32.     string GetGender() const {
  33.         return gender_;
  34.     }
  35.    
  36.     ~Person() {
  37.         cout << "Деструктор класса Person" << endl;
  38.     };
  39.  
  40. private:
  41.     string name_ = "Иван";
  42.     string gender_ = "М";
  43.     int age_ = 33;
  44. };
  45.  
  46.  
  47. // Рабочий. Владеет несколькими специальностями
  48. class Worker : public Person {
  49. public:
  50.     Worker() {
  51.         cout << "Вызываем конструктор по умолчанию" << endl;
  52.     };
  53.  
  54.    /* Worker() : Person("Гена") {
  55.         cout << "Вызываем параметризованный" << endl;
  56.     };
  57.  
  58.     Worker() : Person("Гена", 33) {
  59.         cout << "Вызываем другой параметризованный конструктор" << endl;
  60.     };*/
  61.  
  62.     Worker(string name, int age) :Person(name, age) {
  63.         cout << "Вызываем другой параметризованный конструктор" << endl;
  64.     };
  65.  
  66.     void AddSpeciality(string speciality) {
  67.         specialties_.insert(speciality);
  68.     }
  69.     bool HasSpeciality(string speciality) const {
  70.         return specialties_.count(speciality);
  71.     }
  72.  
  73.     ~Worker() {
  74.         cout << "Деструктор класса Worker" << endl;
  75.     };
  76.  
  77. private:
  78.     set<string> specialties_;
  79. };
  80.  
  81.  
  82. int main() {
  83.     setlocale(LC_ALL, "ru");
  84.  
  85.     Worker wr;
  86.  
  87.     cout << wr.GetName() << endl;
  88.  
  89.     //Worker wr2("Гена", 33);
  90.  
  91.     //cout << wr2.GetName() << endl;
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement