Advertisement
Derga

Untitled

Dec 4th, 2023
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.08 KB | None | 0 0
  1. //служащий персона рабочий инженер
  2.  
  3. //методы свойства конструкторы и декструкторы
  4.  
  5. #include <algorithm>
  6. #include <iostream>
  7. #include <string>
  8. #include <unordered_set>
  9. #include <vector>
  10.  
  11. using namespace std;
  12.  
  13. class Address {
  14.     string city_ = "";
  15.     string street_ = "";
  16.     size_t house_number_ = 0;
  17.     size_t building_ = 0;
  18.     size_t entrance_ = 0;
  19.     string doorphone_ = "";
  20.     size_t flat_ = 0;
  21.    
  22. public:
  23.     Address() {}
  24.     Address(const string& city, const string& street, size_t house_number,
  25.         size_t building, size_t entrance, string doorphone, size_t flat)
  26.         : city_(city)
  27.         , street_(street)
  28.         , house_number_(house_number)
  29.         , building_(building)
  30.         , entrance_(entrance)
  31.         , doorphone_(doorphone)
  32.         , flat_(flat)
  33.     {}
  34.  
  35.     Address(const Address& address) :
  36.         Address(address.city_, address.street_, address.house_number_,
  37.             address.building_, address.entrance_, address.doorphone_, address.flat_)
  38.     {}
  39.  
  40.     ~Address() {}
  41.  
  42.     Address operator=(const Address& address) {
  43.         return Address(address);
  44.     }
  45.    
  46.     string GetCity() { return city_; }
  47.     string GetStreet() { return street_; }
  48.     size_t GetGouseNumber() { return house_number_; }
  49.     size_t GetBuilding() { return building_; }
  50.     size_t GetEntrance() { return entrance_; }
  51.     string GetDoorphone() { return doorphone_; }
  52.     size_t GetFlat() { return flat_; }
  53.  
  54.     void SetCity(const string& city) { city_ = city; }
  55.     void SetStreet(const string street) { street_ = street; }
  56.     void SetGouseNumber(size_t house_number) { house_number_ = house_number; }
  57.     void SetBuilding(size_t building) { building_ = building; }
  58.     void SetEntrance(size_t entrance) { entrance_ = entrance; }
  59.     void SetDoorphone(const string& doorphone) { doorphone_ = doorphone; }
  60.     void SetFlat(size_t flat) { flat_ = flat; }
  61.  
  62.     void Reset() {
  63.         city_ = "";
  64.         street_ = "";
  65.         house_number_ = 0;
  66.         building_ = 0;
  67.         entrance_ = 0;
  68.         doorphone_ = "";
  69.         flat_ = 0;
  70.     }
  71. };
  72.  
  73. class Date {
  74. private:
  75.     size_t year_;
  76.     size_t month_;
  77.     size_t day_;
  78.  
  79. public:
  80.     Date(size_t year, size_t month, size_t day) : year_(year), month_(month), day_(day) {};
  81.     Date(size_t month, size_t day) : Date(0, month, day) {};
  82.     Date(size_t day) : Date(0, 0, day) {}
  83.     Date() : Date(0, 0, 0) {}
  84.     Date(const Date& date) : Date(date.year_, date.month_, date.day_) {}
  85.     ~Date() {}
  86.  
  87.     Date operator=(const Date& date) {
  88.         return Date(date.year_, date.month_, date.day_);
  89.     }
  90.  
  91.     size_t GetYear() const {
  92.         return year_;
  93.     }
  94.     size_t GetMonth() const {
  95.         return month_;
  96.     }
  97.     size_t GetDay() const {
  98.         return day_;
  99.     }
  100.     void SetYear(size_t year) {
  101.         year_ = year;
  102.     }
  103.     void SetMonth(size_t month) {
  104.         month_ = month;
  105.     }
  106.     void SetDay(size_t day) {
  107.         day_ = day;
  108.     }
  109. };
  110.  
  111. bool operator<(const Date& lhs, const Date& rhs) {
  112.     if (lhs.GetYear() != rhs.GetYear()) {
  113.         return lhs.GetYear() < rhs.GetYear();
  114.     }
  115.     if (lhs.GetMonth() != rhs.GetMonth()) {
  116.         return lhs.GetMonth() < rhs.GetMonth();
  117.     }
  118.     return lhs.GetDay() < rhs.GetDay();
  119. }
  120.  
  121. class Person {
  122. private:
  123.     string surname_ = "";
  124.     string name_  = "";
  125.     string patronymic_ = "";
  126.     bool is_male_ = false;
  127.     size_t age_ = 0;
  128.  
  129.     Date date_of_birth_;
  130.    
  131.     Address residence_;
  132.     Address registration_;
  133.  
  134. public:
  135.     Person(const string& surname, const string& name, const string& patronymic,
  136.         bool is_male, size_t age, const Date& date, const Address& residence, const Address& registration)
  137.         : surname_(surname)
  138.         , name_(name)
  139.         , patronymic_(patronymic)
  140.         , is_male_(is_male)
  141.         , age_(age)
  142.         , date_of_birth_(date)
  143.         , residence_(residence)
  144.         , registration_(registration)
  145.     {}
  146.    
  147.     Person(const string& surname, const string& name, const string& patronymic,
  148.         bool is_male, size_t age, const Date& date, const Address& residence)
  149.         : surname_(surname)
  150.         , name_(name)
  151.         , patronymic_(patronymic)
  152.         , is_male_(is_male)
  153.         , age_(age)
  154.         , date_of_birth_(date)
  155.         , residence_(residence)
  156.     {}
  157.    
  158.     Person(const string& surname, const string& name, const string& patronymic,
  159.         bool is_male, size_t age, const Date& date)
  160.         : surname_(surname)
  161.         , name_(name)
  162.         , patronymic_(patronymic)
  163.         , is_male_(is_male)
  164.         , age_(age)
  165.         , date_of_birth_(date)
  166.     {}
  167.    
  168.     Person(const string& surname, const string& name, const string& patronymic,
  169.         bool is_male, size_t age)
  170.         : surname_(surname)
  171.         , name_(name)
  172.         , patronymic_(patronymic)
  173.         , is_male_(is_male)
  174.         , age_(age)
  175.     {}
  176.  
  177.     Person(const string& surname, const string& name, const string& patronymic,
  178.         bool is_male)
  179.         : surname_(surname)
  180.         , name_(name)
  181.         , patronymic_(patronymic)
  182.         , is_male_(is_male)
  183.     {}
  184.    
  185.     Person(const string& surname, const string& name, const string& patronymic)
  186.         : surname_(surname)
  187.         , name_(name)
  188.         , patronymic_(patronymic)
  189.     {}
  190.  
  191.     Person(const string& surname, const string& name)
  192.         : surname_(surname)
  193.         , name_(name)
  194.     {}
  195.  
  196.     Person(const string& name)
  197.         : name_(name)
  198.     {}
  199.  
  200.     Person() {}
  201.  
  202.     Person(const Person& person)
  203.         : Person(person.surname_, person.name_, person.patronymic_, person.is_male_,
  204.             person.age_, person.date_of_birth_,
  205.             person.residence_, person.registration_)
  206.     {}
  207.    
  208.     ~Person() {}
  209.  
  210.     Person operator= (const Person & person){
  211.         return Person(person);
  212.     }
  213.  
  214.     void SetSurname(const string& surname) {
  215.         surname_ = surname;
  216.     }
  217.     void SetName(const string& name) {
  218.         name_ = name;
  219.     }
  220.     void SetPatronymic(const string& patrnomic) {
  221.         patronymic_ = patrnomic;
  222.     }
  223.     void SetIsMale(bool is_male) {
  224.         is_male_ = is_male;
  225.     }
  226.     void SetAge(size_t age) {
  227.         age_ = age;
  228.     }
  229.     void SetDateOfBirth(const Date& date) {
  230.         date_of_birth_ = date;
  231.     }
  232.     void SetResidenceAddress(const Address& address) {
  233.         residence_ = address;
  234.     }
  235.     void SetRegistrationAddress(const Address& address) {
  236.         registration_ = address;
  237.     }
  238.    
  239.     string GetSurname() const {
  240.         return surname_;
  241.     }
  242.     string GetName() const {
  243.         return name_;
  244.     }
  245.     string GetPatronymic() const {
  246.         return patronymic_;
  247.     }
  248.     bool GetIsMale() const {
  249.         return is_male_;
  250.     }
  251.     size_t GetAge() const {
  252.         return age_;
  253.     }
  254.     Date GetDateOfBirth() const {
  255.         return date_of_birth_;
  256.     }
  257.     Address GetResidenceAddress() const {
  258.         return residence_;
  259.     }
  260.     Address GetRegistrationAddress() const {
  261.         return registration_;
  262.     }
  263. };
  264.  
  265. class Employee : public Person {
  266.     Address address_;
  267.     string name_of_company_ = "";
  268.     bool got_job_ = false;
  269.  
  270. public:
  271.     Employee(const string& surname, const string& name, const string& patronymic,
  272.         bool is_male, size_t age, const Date& date, const Address& residence, const Address& registration,
  273.         Address& address, const string& name_of_company, bool got_job)
  274.         : Person(surname, name, patronymic, is_male, age, date, residence, registration)
  275.         , address_(address)
  276.         , name_of_company_(name_of_company)
  277.         , got_job_(got_job)
  278.     {}
  279.  
  280.  
  281.     Employee(Address& address, const string& name_of_company, bool got_job)
  282.         : Person()
  283.         , address_(address)
  284.         , name_of_company_(name_of_company)
  285.         , got_job_(got_job)
  286.     {}
  287.  
  288.     Employee(Address& address, const string& name_of_company)
  289.         : Person()
  290.         , address_(address)
  291.         , name_of_company_(name_of_company)
  292.     {}
  293.  
  294.     Employee(const string& name_of_company)
  295.         : Person()
  296.         , name_of_company_(name_of_company)
  297.     {}
  298.  
  299.     Employee() : Person() {}
  300.  
  301.     string GetCompanyName() const  {
  302.         return name_of_company_;
  303.     }
  304.     Address GetCompanyAddress() const  {
  305.         return address_;
  306.     }
  307.     bool GetGotJob() const {
  308.         return got_job_;
  309.     }
  310.  
  311.     void SetCompanyName(const string& name_of_company) {
  312.         name_of_company_ = name_of_company;
  313.     }
  314.     void SetCompanyAddress(const Address& address) {
  315.         address_ = address;
  316.     }
  317.     void SetGotJob(bool got_job) {
  318.         got_job_ = got_job;
  319.     }
  320.    
  321.     void ToQuitJob() {
  322.         got_job_ = false;
  323.         name_of_company_ = "";
  324.         address_.Reset();
  325.     }
  326. };
  327.  
  328. class Worker : virtual public Person {
  329. private:
  330.     unordered_set<string> specialisations_;
  331. public:
  332.     unordered_set<string> GetSpecializations() { return specialisations_; }
  333.     Worker(const unordered_set<string>& specializations) : specialisations_(specializations) {}
  334.     Worker() {}
  335.     Worker(const Worker& worker) : specialisations_(worker.specialisations_) {}
  336.     ~Worker() {}
  337.     Worker operator=(const Worker& worker) { return Worker(worker); }
  338.    
  339.     void SetSpecialization(const unordered_set<string>& specializations) { specialisations_ = specializations; }
  340.     void PrintSpecializations() const  {
  341.         for (auto& spec : specialisations_) {
  342.             cout << spec << ' ';
  343.         }
  344.     }
  345.     void AddSpecialization(const string& specialization) {
  346.         specialisations_.insert(specialization);
  347.     }
  348.     void DeleteSpecialization(const string& specialization) {
  349.         specialisations_.erase(specialization);
  350.     }
  351.     void ChangeSpecialization(const string& from, const string& to) {
  352.         DeleteSpecialization(from);
  353.         specialisations_.insert(to);
  354.     }
  355. };
  356.  
  357. class Engineer : virtual public Employee {
  358.     vector<Worker> workers_;
  359. public:
  360.     //Engineer(const Engineer& engineer) {}
  361.     //Engineer operator=(const Engineer& engineer) {}
  362.  
  363.     void AddWorker(const Worker& worker) {
  364.         workers_.push_back(worker);
  365.     }
  366.     void DismissWorker(const string& specialization) {
  367.         for (auto worker = workers_.begin(); worker != workers_.end(); ++worker) {
  368.             const auto& worker_specializations = worker->GetSpecializations();
  369.             if (worker_specializations.find(specialization) != worker_specializations.end()) {
  370.                 workers_.erase(worker);
  371.                 return;
  372.             }
  373.         }
  374.     }
  375.     void DismissAllWorkers() {
  376.         workers_.clear();
  377.     }
  378.     void PrintWorkers() {
  379.         for (const auto& worker : workers_) {
  380.             worker.PrintSpecializations();
  381.             cout << '\n';
  382.        }
  383.     }
  384.     void SortWorkersByBirthDate() {
  385.         sort(begin(workers_), end(workers_), [](const Worker& lhs, const Worker& rhs) {
  386.             return lhs.GetDateOfBirth() < rhs.GetDateOfBirth();
  387.         });
  388.     }
  389. };
  390.  
  391. class EngeneerWorker : public Engineer, public Worker {
  392.  
  393. };
  394.  
  395. int main() {
  396.  
  397. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement