Advertisement
Metaraddin

Lab. 4, var 13

Jul 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. class CDate {
  7. private:
  8.     int _day;
  9.     int _month;
  10.     int _year;
  11.  
  12. public:
  13.     CDate(int day, int month, int year) {
  14.         if (year < 1990) { _year = 1990;  }
  15.         else if (year > 2020) { _year = 2020; }
  16.         else { _year = year; }
  17.  
  18.         if (month < 1) { _month = 1; }
  19.         else if (month > 12) { _month = 12; }
  20.         else { _month = month; }
  21.  
  22.         if (day < 1) { _day = 1; }
  23.         else if (_month == 1 || _month == 3 ||
  24.             _month == 5 || _month == 7 ||
  25.             _month == 8 || _month == 10 || _month == 12) {
  26.             if (day > 31) { _day = 31; }
  27.             else { _day = day; }
  28.         }
  29.         else if (_month == 4 || _month == 6 ||
  30.             _month == 9 || _month == 11) {
  31.             if (day > 30) { _day = 31; }
  32.             else { _day = day; }
  33.         }
  34.         else {
  35.             if (_year % 4 == 0) {
  36.                 if (day > 29) { _day = 29; }
  37.                 else { _day = day; }
  38.             }
  39.             else {
  40.                 if (day > 28) { _day = 28; }
  41.                 else { _day = day; }
  42.             }
  43.         }
  44.     }
  45.  
  46.     int getDay() { return _day; }
  47.     int getMonth() { return _month; }
  48.     int getYear() { return _year; }
  49.  
  50.     string format() {
  51.         return (to_string(_day) + "." + to_string(_month) + "." + to_string(_year));
  52.     }
  53. };
  54.  
  55. class CResident {
  56. private:
  57.     string _surname;
  58.     string _name;
  59.     string _pat;
  60.     string _address;
  61.     string _workAddress;
  62.     bool _vaccine;
  63.     CDate _date;
  64.  
  65. public:
  66.     CResident(string surname = "None",
  67.         string name = "None",
  68.         string pat = "None",
  69.         string address = "None",
  70.         string workAddress = "None",
  71.         bool vaccine = false,
  72.         int day = 1,
  73.         int month = 1,
  74.         int year = 1990) :
  75.         _surname{ surname },
  76.         _name{ name },
  77.         _pat{ pat },
  78.         _address{ address },
  79.         _workAddress{ workAddress },
  80.         _vaccine{ vaccine },
  81.         _date{ CDate(day, month, year) } {
  82.     }
  83.  
  84.     string getSurname() { return _surname; }
  85.     string getName() { return _name; }
  86.     string getPat() { return _pat; }
  87.     string getAddress() { return _address; }
  88.     string getWorkAddress() { return _workAddress; }
  89.     bool getVaccine() { return _vaccine; }
  90.     int getDateDay() { return _date.getDay(); }
  91.     int getDateMonth() { return _date.getMonth(); }
  92.     int getDateYear() { return _date.getYear(); }
  93.  
  94.     void setSurname(string inp) { _surname = inp; }
  95.     void setName(string inp) { _name = inp; }
  96.     void setPat(string inp) { _pat = inp; }
  97.     void setAddress(string inp) { _address = inp; }
  98.     void setWorkAddress(string inp) { _workAddress = inp; }
  99.     void setVaccine(bool inp) { _vaccine = inp; }
  100.     void setDate(int day, int month, int year) { _date = CDate(day, month, year); }
  101.  
  102.     string format() {
  103.         string vaccine;
  104.         if (_vaccine == true) { vaccine = "Done"; }
  105.         else { vaccine = "No vaccination"; }
  106.         return ("Name: " + _name +
  107.             "\nSurname: " + _surname +
  108.             "\nPatronymic: " + _pat +
  109.             "\nAddress: " + _address +
  110.             "\nWork Address: " + _workAddress +
  111.             "\nAvailability of vaccination: " + vaccine +
  112.             "\nDate of fluorography: " + _date.format());
  113.     }
  114. };
  115.  
  116. class CPolyclinic {
  117. private:
  118.     vector <CResident> kit;
  119.  
  120. public:
  121.     CPolyclinic() {};
  122.  
  123.     CResident getResident(int ind) { return kit.at(ind); }
  124.     void setResident(int ind, CResident inp) { kit.at(ind) = inp; }
  125.  
  126.     void addResident(CResident inp) { kit.push_back(inp); }
  127.     void delResident(int ind) {
  128.         auto iter = kit.cbegin();
  129.         kit.erase(iter + ind);
  130.     }
  131.  
  132.     string format() {
  133.         string res = "List of residents:\n";
  134.         for (int i = 0; i < kit.size(); i++) {
  135.             res += "(N" + to_string(i) + ") " + kit.at(i).format() + "\n\n";
  136.         }
  137.         return res;
  138.     }
  139.  
  140.     string noVaccineList() {
  141.         string res = "No vaccine list:\n";
  142.         for (int i = 0; i < kit.size(); i++) {
  143.             if (kit.at(i).getVaccine() == false) {
  144.                 res += "(N" + to_string(i) + ") " + kit.at(i).format() + "\n\n";
  145.             }
  146.         }
  147.         return res;
  148.     }
  149.  
  150.     void sort() {
  151.         for (int i = 1; i < kit.size(); i++) {
  152.             for (int j = i; j > 0 && kit.at(j - 1).getDateDay() > kit.at(j).getDateDay(); j--) {
  153.                 swap(kit.at(j - 1), kit.at(j));
  154.             }
  155.         }
  156.         for (int i = 1; i < kit.size(); i++) {
  157.             for (int j = i; j > 0 && kit.at(j - 1).getDateMonth() > kit.at(j).getDateMonth(); j--) {
  158.                 swap(kit.at(j - 1), kit.at(j));
  159.             }
  160.         }
  161.         for (int i = 1; i < kit.size(); i++) {
  162.             for (int j = i; j > 0 && kit.at(j - 1).getDateYear() > kit.at(j).getDateYear(); j--) {
  163.                 swap(kit.at(j - 1), kit.at(j));
  164.             }
  165.         }
  166.     }
  167. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement