Advertisement
gasaichan

TEST

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