Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <set>
- struct Console {
- static void cyrillic() {
- system("chcp 1251 > nul");
- }
- static void clear() {
- system("cls");
- }
- static void pause() {
- system("pause > nul");
- }
- static void flush(std::istream& stream = std::cin) {
- stream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- }
- };
- using namespace std;
- struct Address {
- string country;
- string city;
- string street;
- string house;
- friend bool operator<(const Address& a, const Address& b) {
- if (a.country < b.country) return true;
- else if (a.country == b.country) {
- if (a.city < b.city) return true;
- else if (a.city == b.city) {
- if (a.street < b.street) return true;
- else if (a.street == b.street) {
- return a.house < b.house;
- }
- }
- }
- return false;
- }
- friend bool operator==(const Address& a, const Address& b) {
- return a.country == b.country
- && a.city == b.city
- && a.street == b.street
- && a.house == b.house;
- }
- };
- struct Birthday {
- Birthday() : year(1900), month(1), day(1) {}
- int year;
- int month;
- int day;
- string show()const {
- auto dd = to_string(day);
- auto mm = to_string(month);
- auto date = day < 10 ? "0"s + dd : dd;
- date += month < 10 ? ".0"s + mm : "."s + mm;
- date += "."s + to_string(year);
- return date;
- }
- friend bool operator<(const Birthday& a, const Birthday& b) {
- if (a.year < b.year) return true;
- else if (a.year == b.year) {
- if (a.month < b.month) return true;
- else if (a.year < b.year) {
- return a.day < b.day;
- }
- }
- return false;
- }
- friend bool operator==(const Birthday& a, const Birthday& b) {
- return a.year == b.year
- && a.month == b.month
- && a.day == b.day;
- }
- };
- struct Anthropometry {
- Anthropometry() : weight(.0), growth(.0) {}
- string hair_color;
- string sex;
- double weight;
- double growth;
- friend bool operator<(const Anthropometry& a, const Anthropometry& b) {
- return a.growth < b.growth;
- }
- friend bool operator==(const Anthropometry& a, const Anthropometry& b) {
- return a.growth == b.growth;
- }
- };
- struct Person {
- string name;
- Address address;
- Anthropometry anthropometry;
- Birthday birthday;
- int age()const {
- tm sys_time;
- __time64_t time;
- _time64(&time);
- _localtime64_s(&sys_time, &time);
- auto year = sys_time.tm_year + 1900;
- auto month = sys_time.tm_mon + 1;
- auto day = sys_time.tm_mday;
- auto diff = year - birthday.year;
- if (month < birthday.month || (month == birthday.month && day < birthday.day)) --diff;
- return diff;
- }
- friend bool operator<(const Person& a, const Person& b) {
- if (a.name < b.name) return true;
- else if (a.name == b.name) {
- if (a.birthday < b.birthday) return true;
- else if (a.birthday == b.birthday) {
- if (a.address < b.address) return true;
- else if (a.address == b.address) {
- return a.anthropometry < b.anthropometry;
- }
- }
- }
- return false;
- }
- };
- Person input_person() {
- Person person;
- cout << "Ф.И.О.: ";
- getline(cin, person.name);
- cout << "Год рождения в формате YYYY: ";
- cin >> person.birthday.year;
- cout << "Месяц рождения в формате (1-12): ";
- cin >> person.birthday.month;
- cout << "Число рождения в формате (1-31): ";
- cin >> person.birthday.day;
- Console::flush();
- cout << "Страна: ";
- getline(cin, person.address.country);
- cout << "Населённый пункт: ";
- getline(cin, person.address.city);
- cout << "Улица: ";
- getline(cin, person.address.street);
- cout << "Дом-квартира: ";
- getline(cin, person.address.house);
- cout << "Рост (в сантиметрах): ";
- cin >> person.anthropometry.growth;
- cout << "Вес (в килограммах): ";
- cin >> person.anthropometry.weight;
- Console::flush();
- cout << "Пол: ";
- cin >> person.anthropometry.sex;
- cout << "Цвет волос: ";
- cin >> person.anthropometry.hair_color;
- Console::clear();
- Console::flush();
- return person;
- }
- void output_person(const Person& person) {
- cout << person.name << '\n'
- << " - Дата рождения: " << person.birthday.show() << '\n'
- << " - Возраст: " << person.age() << '\n'
- << " - Адрес:\n"
- << "\t- Страна: " << person.address.country << '\n'
- << "\t- Населённый пункт: " << person.address.city << '\n'
- << "\t- Улица: " << person.address.street << '\n'
- << "\t- Дом-квартира: " << person.address.house << '\n'
- << " - Антропологические данные:\n"
- << "\t- Пол: " << person.anthropometry.sex << '\n'
- << "\t- Рост: " << person.anthropometry.growth << '\n'
- << "\t- Вес: " << person.anthropometry.weight << '\n'
- << "\t- Цвет волос: " << person.anthropometry.hair_color << '\n';
- }
- int main() {
- Console::cyrillic();
- set<Person> persons;
- for (auto i = 0; i < 2; ++i) {
- auto person = input_person();
- persons.insert(person);
- }
- for (const auto& person : persons) {
- output_person(person);
- cout.put('\n');
- }
- Console::pause();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement