Advertisement
kirill_76rus

name

Nov 6th, 2020
2,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. #include<string>
  4. #include<vector>
  5. using namespace std;
  6. class Person {
  7. private:
  8.     map <int, string> surname;
  9.     map<int, string> name;
  10. public:
  11.     void ChangeFirstName(int year, const string& first_name) {
  12.       name[year] = first_name;/*add first name at year*/
  13.     }
  14.     void ChangeLastName(int year, const string& last_name) {
  15.     surname[year] = last_name;
  16.         // добавить факт изменения фамилии на last_name в год year
  17.     }
  18.     string GetFullName(int year) {
  19.         // получить имя и фамилию по состоянию на конец года
  20.         string finded_name, finded_surname;
  21.         int temp_year = 0U;
  22.         for (auto n : name) {
  23.             if (n.first > temp_year && n.first <= year) {
  24.             finded_name = n.second;
  25.             }
  26.         }
  27.         temp_year = 0U;
  28.         for (auto s : surname) {
  29.             if (s.first > temp_year && s.first <= year) {
  30.             finded_surname = s.second;
  31.             }
  32.         }
  33.         if (finded_name != "" && finded_surname != "") {
  34.             return finded_name+" "+finded_surname;
  35.         }
  36.         else if (finded_name != "" && finded_surname == "") {
  37.             return finded_name+ " with unknown last name";
  38.         }
  39.         else {
  40.             return "Incognito";
  41.         }
  42.         }
  43. };
  44. int main(void) {
  45.     Person person;
  46.  
  47.     person.ChangeFirstName(1965, "Polina");
  48.     person.ChangeLastName(1967, "Sergeeva");
  49.     for (int year : {1900, 1965, 1990}) {
  50.         cout << person.GetFullName(year) << endl;
  51.     }
  52.  
  53.     person.ChangeFirstName(1970, "Appolinaria");
  54.     for (int year : {1969, 1970}) {
  55.         cout << person.GetFullName(year) << endl;
  56.     }
  57.  
  58.     person.ChangeLastName(1968, "Volkova");
  59.     for (int year : {1969, 1970}) {
  60.         cout << person.GetFullName(year) << endl;
  61.     }
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement