Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <vector>
- using namespace std;
- class CDate {
- private:
- int _day;
- int _month;
- int _year;
- public:
- CDate(int day, int month, int year) {
- if (year < 1990) { _year = 1990; }
- else if (year > 2020) { _year = 2020; }
- else { _year = year; }
- if (month < 1) { _month = 1; }
- else if (month > 12) { _month = 12; }
- else { _month = month; }
- if (day < 1) { _day = 1; }
- else if (_month == 1 || _month == 3 ||
- _month == 5 || _month == 7 ||
- _month == 8 || _month == 10 || _month == 12) {
- if (day > 31) { _day = 31; }
- else { _day = day; }
- }
- else if (_month == 4 || _month == 6 ||
- _month == 9 || _month == 11) {
- if (day > 30) { _day = 31; }
- else { _day = day; }
- }
- else {
- if (_year % 4 == 0) {
- if (day > 29) { _day = 29; }
- else { _day = day; }
- }
- else {
- if (day > 28) { _day = 28; }
- else { _day = day; }
- }
- }
- }
- int getDay() { return _day; }
- int getMonth() { return _month; }
- int getYear() { return _year; }
- string format() {
- return (to_string(_day) + "." + to_string(_month) + "." + to_string(_year));
- }
- };
- class CResident {
- private:
- string _surname;
- string _name;
- string _pat;
- string _address;
- string _workAddress;
- bool _vaccine;
- CDate _date;
- public:
- CResident(string surname = "None",
- string name = "None",
- string pat = "None",
- string address = "None",
- string workAddress = "None",
- bool vaccine = false,
- int day = 1,
- int month = 1,
- int year = 1990) :
- _surname{ surname },
- _name{ name },
- _pat{ pat },
- _address{ address },
- _workAddress{ workAddress },
- _vaccine{ vaccine },
- _date{ CDate(day, month, year) } {
- }
- string getSurname() { return _surname; }
- string getName() { return _name; }
- string getPat() { return _pat; }
- string getAddress() { return _address; }
- string getWorkAddress() { return _workAddress; }
- bool getVaccine() { return _vaccine; }
- int getDateDay() { return _date.getDay(); }
- int getDateMonth() { return _date.getMonth(); }
- int getDateYear() { return _date.getYear(); }
- void setSurname(string inp) { _surname = inp; }
- void setName(string inp) { _name = inp; }
- void setPat(string inp) { _pat = inp; }
- void setAddress(string inp) { _address = inp; }
- void setWorkAddress(string inp) { _workAddress = inp; }
- void setVaccine(bool inp) { _vaccine = inp; }
- void setDate(int day, int month, int year) { _date = CDate(day, month, year); }
- string format() {
- string vaccine;
- if (_vaccine == true) { vaccine = "Done"; }
- else { vaccine = "No vaccination"; }
- return ("Name: " + _name +
- "\nSurname: " + _surname +
- "\nPatronymic: " + _pat +
- "\nAddress: " + _address +
- "\nWork Address: " + _workAddress +
- "\nAvailability of vaccination: " + vaccine +
- "\nDate of fluorography: " + _date.format());
- }
- };
- class CPolyclinic {
- private:
- vector <CResident> kit;
- public:
- CPolyclinic() {};
- CResident getResident(int ind) { return kit.at(ind); }
- void setResident(int ind, CResident inp) { kit.at(ind) = inp; }
- void addResident(CResident inp) { kit.push_back(inp); }
- void delResident(int ind) {
- auto iter = kit.cbegin();
- kit.erase(iter + ind);
- }
- string format() {
- string res = "List of residents:\n";
- for (int i = 0; i < kit.size(); i++) {
- res += "(N" + to_string(i) + ") " + kit.at(i).format() + "\n\n";
- }
- return res;
- }
- string noVaccineList() {
- string res = "No vaccine list:\n";
- for (int i = 0; i < kit.size(); i++) {
- if (kit.at(i).getVaccine() == false) {
- res += "(N" + to_string(i) + ") " + kit.at(i).format() + "\n\n";
- }
- }
- return res;
- }
- void sort() {
- for (int i = 1; i < kit.size(); i++) {
- for (int j = i; j > 0 && kit.at(j - 1).getDateDay() > kit.at(j).getDateDay(); j--) {
- swap(kit.at(j - 1), kit.at(j));
- }
- }
- for (int i = 1; i < kit.size(); i++) {
- for (int j = i; j > 0 && kit.at(j - 1).getDateMonth() > kit.at(j).getDateMonth(); j--) {
- swap(kit.at(j - 1), kit.at(j));
- }
- }
- for (int i = 1; i < kit.size(); i++) {
- for (int j = i; j > 0 && kit.at(j - 1).getDateYear() > kit.at(j).getDateYear(); j--) {
- swap(kit.at(j - 1), kit.at(j));
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement