Advertisement
gasaichan

BDZ_15

Dec 10th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <clocale>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. typedef struct Price
  10. {
  11.     string Name;
  12.     string Cost;
  13.     string Section;
  14. };
  15.  
  16. Price StructInit( Price p );
  17. void StructOut( Price p );
  18. void CheckGoods( string Name, Price * p, int n );
  19.  
  20. int main( )
  21. {
  22.     setlocale( LC_ALL, "Russian" );
  23.  
  24.     int n, MenuChoice;
  25.     string Name;
  26.  
  27.     cout << "Введите количество товаров: ";
  28.     cin >> n;
  29.  
  30.     Price * p = new Price[n];
  31.  
  32.     char * Choice = new char[2];
  33.     strcpy_s( Choice, strlen( Choice ), "Y" );
  34.  
  35.     while ( Choice[0] == 'Y' )
  36.     {
  37.         cout << endl << "1. Ввести ценники: " << endl;
  38.         cout << "2. Вывести ценники на экран: " << endl;
  39.         cout << "3. Проверить, есть ли в магазине введенный товар: " << endl;
  40.         cout << "4. Очистить экран. " << endl;
  41.         cout << "5. Выход. " << endl;
  42.  
  43.  
  44.         cout << endl << "Ваш выбор: ";
  45.         for ( ;;)
  46.         {
  47.             cin >> MenuChoice;
  48.             if ( MenuChoice >= 1 && MenuChoice <= 5 ) { break; }
  49.             else { cout << endl << "Повторите ввод: "; continue; }
  50.         }
  51.  
  52.         switch ( MenuChoice )
  53.         {
  54.         case 1:
  55.             for ( int i = 0; i < n; i++ )
  56.             {
  57.                 getchar( );
  58.                 p[i] = StructInit( p[i] );
  59.             }
  60.             break;
  61.         case 2:
  62.             for ( int i = 0; i < n; i++ )
  63.             {
  64.                 StructOut( p[i] );
  65.             }
  66.             break;
  67.         case 3:
  68.             getchar( );
  69.             cout << "Введите название товара для проверки: ";
  70.             getline( cin, Name );
  71.             CheckGoods( Name, p, n );
  72.             break;
  73.         case 4:
  74.             system( "CLS" );
  75.             break;
  76.         case 5:
  77.             system( "EXIT" );
  78.             return 0;
  79.             break;
  80.         }
  81.     }
  82.     _getch( );
  83.  
  84.     return 0;
  85.  
  86. }
  87.  
  88. void StructOut( Price p )
  89. {
  90.     cout << "Название товара: " + p.Name + "; Цена товара: " + p.Cost + "; Секция: " + p.Section << endl;
  91. }
  92.  
  93. Price StructInit( Price p )
  94. {
  95.     cout << "Введите название товара: ";
  96.     getline( cin, p.Name );
  97.  
  98.     cout << "Введите цену товара: ";
  99.     cin >> p.Cost;
  100.  
  101.     cout << "Введите секцию: ";
  102.     cin >> p.Section;
  103.  
  104.     return p;
  105. }
  106.  
  107. void CheckGoods( string Name, Price * p, int n )
  108. {
  109.     for ( int i = 0; i < n; i++ )
  110.     {
  111.         if ( p[i].Name == Name ) { StructOut( p[i] ); }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement