Advertisement
gasaichan

14

May 6th, 2018
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <clocale>
  5.  
  6. using namespace std;
  7.  
  8. struct client {
  9.     string surname;
  10.     string country;
  11.     int year;
  12.     int price;
  13. };
  14.  
  15. void show_sorted_by_year( client clients [], int n ) {
  16.     int changes = 1;
  17.     client temp_client;
  18.     while ( changes != 0 ) {
  19.         for ( int i = 0; i < n; i++ ) {
  20.             changes = 0;
  21.             for ( int j = i + 1; j < n; j++ ) {
  22.                 if ( clients[i].year < clients[j].year ) {
  23.                     temp_client = clients[i];
  24.                     clients[i] = clients[j];
  25.                     clients[j] = temp_client;
  26.                     changes++;
  27.                 }
  28.             }
  29.         }
  30.     }
  31.  
  32.     cout << "Отсортированный массив клиентов по убыванию года турпоездки: " << endl;
  33.     for ( int i = 0; i < n; i++ ) {
  34.         cout << "Фамилия: " << clients[i].surname << "; Страна: " << clients[i].country << "; Год: " << clients[i].year << "; Стоимость: " << clients[i].price << endl;
  35.     }
  36. }
  37.  
  38. void show_by_price( client clients [], int n, int X) {
  39.     cout << "Клиенты, стоимость  тура которых не превышает " << X << " гривен. " << endl;
  40.     for ( int i = 0; i < n; i++ ) {
  41.         if ( clients[i].price <= X ) {
  42.             cout << "Фамилия: " << clients[i].surname << "; Страна: " << clients[i].country << "; Год: " << clients[i].year << "; Стоимость: " << clients[i].price << endl;
  43.         }
  44.     }
  45. }
  46.  
  47. int main( )
  48. {
  49.  
  50.     setlocale( LC_ALL, "Russian" );
  51.     const int n = 4;
  52.     client arr[n] = {
  53.         "dsadasdsa", "r", 1990, 290292,
  54.         "dsadas", "dsa", 15483, 20222,
  55.         "asdsa", "asdas", 200, 309340,
  56.         "asdsad", "asdsao", 333333,  200000
  57.     };
  58.  
  59.     show_sorted_by_year( arr, n );
  60.     cout << endl << endl;
  61.     show_by_price( arr, n, 150000 );
  62.  
  63.     _getch( );
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement