Vla_DOS

array

May 8th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3. #include <iostream>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. class People {
  8. public:
  9.     string surName;
  10.     string cityName;
  11.     string adress;
  12.  
  13. };
  14.  
  15. void Input(People* l, int n) {
  16.     string surName, cityName, adress;
  17.  
  18.  
  19.     for (int i = 0; i < n; i++) {
  20.         cout << "Введiть прiзвище: ";
  21.         cin >> surName;
  22.  
  23.         cout << "Введiть мiсто: ";
  24.         cin >> cityName;
  25.  
  26.         cout << "Введiть адресу: ";
  27.         cin >> adress;
  28.  
  29.         l[i].surName = surName;
  30.         l[i].cityName = cityName;
  31.         l[i].adress = adress;
  32.  
  33.         cout << endl;
  34.     }
  35. }
  36.  
  37. // Виводимо весь список
  38. void GetList(People* l, int n) {
  39.     for (size_t i = 0; i < n; i++)
  40.         cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  41. }
  42.  
  43. void GetListParameters(People* l, int n) {
  44.     int k = 1;
  45.  
  46.     for (int i = 0; i < n; i++)
  47.         for (int j = i + 1; j < n; j++)
  48.             if (l[i].cityName != l[j].cityName && l[i].adress == l[j].adress) {
  49.                 cout << "SurName: " << l[i].surName << "\t" << "City: " << l[i].cityName << "\t" << "Adress: " << l[i].adress << endl;
  50.                 k++;
  51.                 if (k == 2)break;
  52.             }
  53. }
  54.  
  55.  
  56. int main() {
  57.     setlocale(0, "");
  58.     const int n = 3;
  59.     People l[n];
  60.  
  61.     Input(l, n);
  62.  
  63.     GetList(l, n);
  64.     cout << endl;
  65.     cout << "\n\n";
  66.     GetListParameters(l, n);
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment