Advertisement
NickAndNick

Агрегирование

Sep 10th, 2020
984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <set>
  5. struct Console {
  6.     static void cyrillic() {
  7.         system("chcp 1251 > nul");
  8.     }
  9.     static void clear() {
  10.         system("cls");
  11.     }
  12.     static void pause() {
  13.         system("pause > nul");
  14.     }
  15.     static void flush(std::istream& stream = std::cin) {
  16.         stream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  17.     }
  18. };
  19. using namespace std;
  20. struct Address {
  21.     string country;
  22.     string city;
  23.     string street;
  24.     string house;
  25.     friend bool operator<(const Address& a, const Address& b) {
  26.         if (a.country < b.country) return true;
  27.         else if (a.country == b.country) {
  28.             if (a.city < b.city) return true;
  29.             else if (a.city == b.city) {
  30.                 if (a.street < b.street) return true;
  31.                 else if (a.street == b.street) {
  32.                     return a.house < b.house;
  33.                 }
  34.             }
  35.         }
  36.         return false;
  37.     }
  38.     friend bool operator==(const Address& a, const Address& b) {
  39.         return a.country == b.country
  40.             && a.city == b.city
  41.             && a.street == b.street
  42.             && a.house == b.house;
  43.     }
  44. };
  45. struct Birthday {
  46.     Birthday() : year(1900), month(1), day(1) {}
  47.     int year;
  48.     int month;
  49.     int day;
  50.     string show()const {
  51.         auto dd = to_string(day);
  52.         auto mm = to_string(month);
  53.         auto date = day < 10 ? "0"s + dd : dd;
  54.         date += month < 10 ? ".0"s + mm : "."s + mm;
  55.         date += "."s + to_string(year);
  56.         return date;
  57.     }
  58.     friend bool operator<(const Birthday& a, const Birthday& b) {
  59.         if (a.year < b.year) return true;
  60.         else if (a.year == b.year) {
  61.             if (a.month < b.month) return true;
  62.             else if (a.year < b.year) {
  63.                 return a.day < b.day;
  64.             }
  65.         }
  66.         return false;
  67.     }
  68.     friend bool operator==(const Birthday& a, const Birthday& b) {
  69.         return a.year == b.year
  70.             && a.month == b.month
  71.             && a.day == b.day;
  72.     }
  73. };
  74. struct Anthropometry {
  75.     Anthropometry() : weight(.0), growth(.0) {}
  76.     string hair_color;
  77.     string sex;
  78.     double weight;
  79.     double growth;
  80.     friend bool operator<(const Anthropometry& a, const Anthropometry& b) {
  81.         return a.growth < b.growth;
  82.     }
  83.     friend bool operator==(const Anthropometry& a, const Anthropometry& b) {
  84.         return a.growth == b.growth;
  85.     }
  86. };
  87. struct Person {
  88.     string name;
  89.     Address address;
  90.     Anthropometry anthropometry;
  91.     Birthday birthday;
  92.     int age()const {
  93.         tm sys_time;
  94.         __time64_t time;
  95.         _time64(&time);
  96.         _localtime64_s(&sys_time, &time);
  97.         auto year = sys_time.tm_year + 1900;
  98.         auto month = sys_time.tm_mon + 1;
  99.         auto day = sys_time.tm_mday;
  100.         auto diff = year - birthday.year;
  101.         if (month < birthday.month || (month == birthday.month && day < birthday.day)) --diff;
  102.         return diff;
  103.     }
  104.     friend bool operator<(const Person& a, const Person& b) {
  105.         if (a.name < b.name) return true;
  106.         else if (a.name == b.name) {
  107.             if (a.birthday < b.birthday) return true;
  108.             else if (a.birthday == b.birthday) {
  109.                 if (a.address < b.address) return true;
  110.                 else if (a.address == b.address) {
  111.                     return a.anthropometry < b.anthropometry;
  112.                 }
  113.             }
  114.         }
  115.         return false;
  116.     }
  117. };
  118. Person input_person() {
  119.     Person person;
  120.     cout << "Ф.И.О.: ";
  121.     getline(cin, person.name);
  122.     cout << "Год рождения в формате YYYY: ";
  123.     cin >> person.birthday.year;
  124.     cout << "Месяц рождения в формате (1-12): ";
  125.     cin >> person.birthday.month;
  126.     cout << "Число рождения в формате (1-31): ";
  127.     cin >> person.birthday.day;
  128.     Console::flush();
  129.     cout << "Страна: ";
  130.     getline(cin, person.address.country);
  131.     cout << "Населённый пункт: ";
  132.     getline(cin, person.address.city);
  133.     cout << "Улица: ";
  134.     getline(cin, person.address.street);
  135.     cout << "Дом-квартира: ";
  136.     getline(cin, person.address.house);
  137.     cout << "Рост (в сантиметрах): ";
  138.     cin >> person.anthropometry.growth;
  139.     cout << "Вес (в килограммах): ";
  140.     cin >> person.anthropometry.weight;
  141.     Console::flush();
  142.     cout << "Пол: ";
  143.     cin >> person.anthropometry.sex;
  144.     cout << "Цвет волос: ";
  145.     cin >> person.anthropometry.hair_color;
  146.     Console::clear();
  147.     Console::flush();
  148.     return person;
  149. }
  150. void output_person(const Person& person) {
  151.     cout << person.name << '\n'
  152.         << " - Дата рождения: " << person.birthday.show() << '\n'
  153.         << " - Возраст: " << person.age() << '\n'
  154.         << " - Адрес:\n"
  155.         << "\t- Страна: " << person.address.country << '\n'
  156.         << "\t- Населённый пункт: " << person.address.city << '\n'
  157.         << "\t- Улица: " << person.address.street << '\n'
  158.         << "\t- Дом-квартира: " << person.address.house << '\n'
  159.         << " - Антропологические данные:\n"
  160.         << "\t- Пол: " << person.anthropometry.sex << '\n'
  161.         << "\t- Рост: " << person.anthropometry.growth << '\n'
  162.         << "\t- Вес: " << person.anthropometry.weight << '\n'
  163.         << "\t- Цвет волос: " << person.anthropometry.hair_color << '\n';
  164. }
  165. int main() {
  166.     Console::cyrillic();
  167.     set<Person> persons;
  168.     for (auto i = 0; i < 2; ++i) {
  169.         auto person = input_person();
  170.         persons.insert(person);
  171.     }
  172.     for (const auto& person : persons) {
  173.         output_person(person);
  174.         cout.put('\n');
  175.     }
  176.     Console::pause();
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement