Advertisement
gasaichan

FINALVER

Apr 8th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4.  
  5. enum Usage { BOYS, GIRLS, BOYS_AND_GIRLS };
  6.  
  7. struct Toy {
  8.     std::string toy_name;
  9.     int article;
  10.     int price;
  11.     std::string country;
  12.     Usage use;
  13. };
  14.  
  15.  
  16. const int toys_number = 3;
  17.  
  18. int main( ) {
  19.  
  20.     setlocale( LC_ALL, "Russian" );
  21.  
  22.     Toy toys[toys_number];
  23.     Toy sorted_array[toys_number];
  24.     int usage;
  25.  
  26.     std::cout << "ЗдАрова. Ща будем работать с массивом структур из 10 элементов." << std::endl << std::endl;
  27.  
  28.     unsigned int choice;
  29.  
  30.     while ( true ) {
  31.         std::cout << "1. Ввести игрушки." << std::endl;
  32.         std::cout << "2. Вывести игрушки в алфавитном порядке стран производителей. " << std::endl;
  33.         std::cout << "3. Поиск по цене игрушек и предназначению. " << std::endl;
  34.         std::cout << "4. Выход. " << std::endl;
  35.  
  36.         std::cout << "Ваш выбор: ";
  37.         std::cin >> choice;
  38.         system( "cls" );
  39.  
  40.  
  41.         switch ( choice ) {
  42.         case 1:
  43.             for ( int i = 0; i < toys_number; i++ ) {
  44.                 std::cout << "Введите название " << i + 1 << "-й игрушки: ";
  45.                 std::cin >> toys[i].toy_name;
  46.  
  47.                 std::cout << "Введите артикул " << i + 1 << "-й игрушки: ";
  48.                 std::cin >> toys[i].article;
  49.  
  50.                 std::cout << "Введите страну производителя " << i + 1 << "-й игрушки: ";
  51.                 std::cin >> toys[i].country;
  52.  
  53.                 std::cout << "Введите цену " << i + 1 << "-й игрушки: ";
  54.                 std::cin >> toys[i].price;
  55.  
  56.                 std::cout << "Введите назначение игрушки. " << std::endl
  57.                     << "1. Для мальчиков. " << std::endl
  58.                     << "2. Для девочек." << std::endl
  59.                     << "3. Для всех." << std::endl;
  60.                 std::cin >> usage;
  61.                 if ( usage == 1 ) { toys[i].use = Usage::BOYS; }
  62.                 if ( usage == 2 ) { toys[i].use = Usage::GIRLS; }
  63.                 if ( usage == 3 ) { toys[i].use = Usage::BOYS_AND_GIRLS; }
  64.             }
  65.             break;
  66.         case 2:
  67.             for ( int i = 0; i < toys_number; i++ ) {
  68.                 sorted_array[i].toy_name = toys[i].toy_name;
  69.                 sorted_array[i].country = toys[i].country;
  70.                 sorted_array[i].price = toys[i].price;
  71.                 sorted_array[i].article = toys[i].article;
  72.                 sorted_array[i].use = toys[i].use;
  73.             }
  74.  
  75.             for ( int i = toys_number - 1; i >= 0; i-- )
  76.             {
  77.                 for ( int j = 0; j < i; j++ )
  78.                 {
  79.                     if ( sorted_array[j].country > sorted_array[j + 1].country )
  80.                     {
  81.                         Toy tmp = sorted_array[j];
  82.                         sorted_array[j] = sorted_array[j + 1];
  83.                         sorted_array[j + 1] = tmp;
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             for ( int i = 0; i < toys_number; i++ ) {
  89.                 std::string usage;
  90.                 if ( sorted_array[i].use == Usage::BOYS) { usage = "Для мальчиков."; }
  91.                 if ( sorted_array[i].use == Usage::GIRLS ) { usage = "Для девочек."; }
  92.                 if ( sorted_array[i].use == Usage::BOYS_AND_GIRLS ) { usage = "Для мальчиков и девочек."; }
  93.                 std::cout << "Название игрушки: " << sorted_array[i].toy_name << "; Артикул: " << sorted_array[i].article << "; Страна производитель: " << sorted_array[i].country << "; Цена: " << sorted_array[i].price << "; " << usage << std::endl;
  94.             }
  95.  
  96.             break;
  97.         case 3:
  98.         {
  99.             int find_price;
  100.             int find_use;
  101.             Usage find_usage;
  102.             std::cout << "Введите цену: ";
  103.             std::cin >> find_price;
  104.  
  105.             std::cout << "Введите назначение игрушки. " << std::endl
  106.                 << "1. Для мальчиков. " << std::endl
  107.                 << "2. Для девочек." << std::endl
  108.                 << "3. Для всех." << std::endl;
  109.             std::cin >> find_use;
  110.             if ( find_use == 1 ) { find_usage = Usage::BOYS; }
  111.             if ( find_use == 2 ) { find_usage = Usage::GIRLS; }
  112.             if ( find_use == 3 ) { find_usage = Usage::BOYS_AND_GIRLS; }
  113.  
  114.             for ( int i = 0; i < toys_number; i++ ) {
  115.                 if ( toys[i].price > find_price && toys[i].use == find_usage) {
  116.                     std::string usage;
  117.                     if ( toys[i].use == Usage::BOYS ) { usage = "Для мальчиков."; }
  118.                     if ( toys[i].use == Usage::GIRLS ) { usage = "Для девочек."; }
  119.                     if ( toys[i].use == Usage::BOYS_AND_GIRLS ) { usage = "Для мальчиков и девочек."; }
  120.                     std::cout << "Название игрушки: " << toys[i].toy_name << "; Артикул: " << toys[i].article << "; Страна производитель: " << toys[i].country << "; Цена: " << toys[i].price << "; " << usage << std::endl;
  121.                 }
  122.             }
  123.             break;
  124.         }
  125.         case 4:
  126.             return 0;
  127.             break;
  128.         }
  129.     }
  130.  
  131.    
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement