Advertisement
onezee

console

Feb 23rd, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <Windows.h>
  4. #include <fstream>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9. struct Storage {
  10.     int number;
  11.     string category;
  12.     string brand;
  13.     float OptPrice;
  14.     float RozPrice;
  15.     int count;
  16. };
  17.  
  18. void DisplayCommands(int MaxSize, int size) {
  19.     cout << "Программа учета товаров на складе:" << endl;
  20.     cout << " - расчитана на " << MaxSize << " товаров/товара/товар на складе." << endl;
  21.     cout << " - в базе уже находится " << size << " товаров/товара/товар." << endl;
  22.     cout << "\nСписок доступных команд:" << endl;
  23.     cout << "--------------------------------------------------" << endl;
  24.     cout << "1. Добавление товара в список." << endl;
  25.     cout << "2. Изменить количество товара на складе." << endl;
  26.     cout << "3. Вывод товара по заданной категории (номер, категория, марка)." << endl;
  27.     cout << "4. Вывод всех товаров." << endl;
  28.     cout << "5. Выход." << endl;
  29. }
  30.  
  31. bool Add(int size, Storage *storage) {
  32.     int number;
  33.     string category;
  34.     string brand;
  35.     double OptPrice;
  36.     float RozPrice;
  37.     int count;
  38.  
  39.     bool foo = true;
  40.  
  41.     system("cls");
  42.     cout << "Добавление товара в список. Шаг 1/6" << endl;
  43.     cout << "-------------------------------------------------" << endl;
  44.     cout << "Введите номер товара: ";
  45.     cin >> number;
  46.     for (int i = 0; i < size; i++) {
  47.         cout << number << " - " << storage[i].number << endl;
  48.         if (number == storage[i].number) {
  49.             foo = false;
  50.             system("cls");
  51.             cout << "Товар под таким номером уже существует, попробуйте снова.\n" << endl;
  52.             break;
  53.         }
  54.     }
  55.     if (foo == true) {
  56.         storage[size - 1].number = number;
  57.     }
  58.     else if (foo == false) {
  59.         return foo;
  60.     }
  61.     system("cls");
  62.     cout << "Добавление товара в список. Шаг 2/6: " << endl;
  63.     cout << "-------------------------------------------------" << endl;
  64.     cout << "Введите категорию товара: ";
  65.     cin >> category;
  66.     storage[size - 1].category = category;
  67.     system("cls");
  68.     cout << "Добавление товара в список. Шаг 3/6: " << endl;
  69.     cout << "-------------------------------------------------" << endl;
  70.     cout << "Введите марку товара: ";
  71.     cin >> brand;
  72.     storage[size - 1].brand = brand;
  73.     system("cls");
  74.     cout << "Добавление товара в список. Шаг 4/6: " << endl;
  75.     cout << "-------------------------------------------------" << endl;
  76.     cout << "Введите оптовую цену: ";
  77.     while (!(cin >> OptPrice) || (cin.peek() != '\n')) {
  78.         cin.clear();
  79.         while (cin.get() != '\n');
  80.         system("cls");
  81.         cout << "Не правильный формат ввода. Введите целое, либо вещественное число: ";
  82.     }
  83.     storage[size - 1].OptPrice = OptPrice;
  84.     system("cls");
  85.     cout << "Добавление товара в список. Шаг 5/6: " << endl;
  86.     cout << "-------------------------------------------------" << endl;
  87.     cout << "Введите розничную цену: ";
  88.     while (!(cin >> RozPrice) || (cin.peek() != '\n')) {
  89.         cin.clear();
  90.         while (cin.get() != '\n');
  91.         system("cls");
  92.         cout << "Не правильный формат ввода. Введите целое, либо вещественное число: ";
  93.     }
  94.     storage[size - 1].RozPrice = RozPrice;
  95.     system("cls");
  96.     cout << "Добавление товара в список. Шаг 6/6: " << endl;
  97.     cout << "-------------------------------------------------" << endl;
  98.     cout << "Введите кол-во на складе: ";
  99.     while (!(cin >> count) || (cin.peek() != '\n')) {
  100.         cin.clear();
  101.         while (cin.get() != '\n');
  102.         system("cls");
  103.         cout << "Не правильный формат ввода. Введите целое число: ";
  104.     }
  105.     storage[size - 1].count = count;
  106.     system("cls");
  107.  
  108.     cout << "Товар успешно добавлен!\n" << endl;
  109.     size++;
  110.     return foo;
  111. }
  112.  
  113. void main() {
  114.     setlocale(LC_ALL, "Russian");
  115.     SetConsoleCP(1251);
  116.     SetConsoleOutputCP(1251);
  117.  
  118.     const int MaxSizeStorage = 999;
  119.     int MaxSize = MaxSizeStorage;
  120.     Storage storage[MaxSizeStorage];
  121.     int size = 0;
  122.     int n, b;
  123.  
  124.     DisplayCommands(MaxSizeStorage, size);
  125.  
  126.     cin >> n;
  127.  
  128.     while (n != 5) {
  129.         if (n == 1) {
  130.             if (size == 0) {
  131.                 size++;
  132.                 Add(size, storage);
  133.             }
  134.             else {
  135.                 size++;
  136.                 int foo = Add(size, storage);
  137.                 if (foo == false) {
  138.                     size--;
  139.                 }
  140.             }
  141.            
  142.         }
  143.         else if (n == 2) {
  144.             if (size == 0) {
  145.                 system("cls");
  146.                 cout << "Ни один товар не находится в базе, попробуйте снова.\n" << endl;
  147.             }
  148.             else {
  149.                 int number;
  150.                 bool check = false;
  151.                 system("cls");
  152.                 cout << "Введите номер товара, информацию которого хотите изменить: ";
  153.                 cin >> number;
  154.                 for (int i = 0; i < size; i++) {
  155.                     if (number == storage[i].number) {
  156.                         check = true;
  157.                         system("cls");
  158.                         cout << "Введите новое количество товара с номером - " << number << " : ";
  159.                         cin >> storage[i].count;
  160.                     }
  161.                 }
  162.                 if (check == false) {
  163.                     system("cls");
  164.                     cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
  165.                 }
  166.                 else {
  167.                     system("cls");
  168.                     cout << "Информация успешно изменена.\n" << endl;
  169.                 }
  170.             }
  171.         }
  172.         else if (n == 3) {
  173.             if (size == 0) {
  174.                 system("cls");
  175.                 cout << "Ни один товар не находится в базе, попробуйте снова.\n" << endl;
  176.             }
  177.             else {
  178.                 int m;
  179.                 bool check = false;
  180.                 system("cls");
  181.                 cout << "Укажите категорию для поиска:" << endl;
  182.                 cout << "1. По номеру товара." << endl;
  183.                 cout << "2. По категории товара." << endl;
  184.                 cout << "3. По марке товара." << endl;
  185.                 cin >> m;
  186.  
  187.                 if (m == 1) {
  188.                     int number;
  189.                     system("cls");
  190.                     cout << "Введите номер товара для поиска: ";
  191.                     cin >> number;
  192.                     system("cls");
  193.                     for (int i = 0; i < size; i++) {
  194.                         if (number == storage[i].number) {
  195.                             check = true;
  196.                             cout << "Товар с номером - " << number << " найден. Его остальные данные:" << endl;
  197.                             cout << "Категория: " << storage[i].category << endl;
  198.                             cout << "Марка: " << storage[i].brand << endl;
  199.                             cout << "Цена оптовая: " << storage[i].OptPrice << endl;
  200.                             cout << "Цена розничная: " << storage[i].RozPrice << endl;
  201.                             cout << "Кол-во на складе: " << storage[i].count << endl;
  202.                         }
  203.                     }
  204.                     if (check == false) {
  205.                         system("cls");
  206.                         cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
  207.                     }
  208.                 }
  209.                 else if (m == 2) {
  210.                     string category;
  211.                     system("cls");
  212.                     cout << "Введите категорию товара для поиска: ";
  213.                     cin >> category;
  214.                     system("cls");
  215.                     for (int i = 0; i < size; i++) {
  216.                         if (category == storage[i].category) {
  217.                             check = true;
  218.                             cout << "Товар с категорией - " << category << " найден. Его остальные данные:" << endl;
  219.                             cout << "Номер: " << storage[i].number << endl;
  220.                             cout << "Марка: " << storage[i].brand << endl;
  221.                             cout << "Цена оптовая: " << storage[i].OptPrice << endl;
  222.                             cout << "Цена розничная: " << storage[i].RozPrice << endl;
  223.                             cout << "Кол-во на складе: " << storage[i].count << endl;
  224.                         }
  225.                     }
  226.                     if (check == false) {
  227.                         system("cls");
  228.                         cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
  229.                     }
  230.                 }
  231.                 else if (m == 3) {
  232.                     string brand;
  233.                     system("cls");
  234.                     cout << "Введите марку товара для поиска: ";
  235.                     cin >> brand;
  236.                     system("cls");
  237.                     for (int i = 0; i < size; i++) {
  238.                         if (brand == storage[i].brand) {
  239.                             check = true;
  240.                             cout << "Товар с маркой - " << brand << " найден. Его остальные данные:" << endl;
  241.                             cout << "Номер: " << storage[i].number << endl;
  242.                             cout << "Категория: " << storage[i].category << endl;
  243.                             cout << "Цена оптовая: " << storage[i].OptPrice << endl;
  244.                             cout << "Цена розничная: " << storage[i].RozPrice << endl;
  245.                             cout << "Кол-во на складе: " << storage[i].count << endl;
  246.                         }
  247.                     }
  248.                     if (check == false) {
  249.                         system("cls");
  250.                         cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
  251.                     }
  252.                 }
  253.                 else if (m != 1 && m != 2 && m != 3) {
  254.                     system("cls");
  255.                     cout << "Некорректный выбор данных для поиска. Попробуйте еще раз.\n" << endl;
  256.                 }
  257.                 else {
  258.                     cout << "\nПоиск выполнен." << endl;
  259.                 }
  260.             cout << endl;
  261.             }
  262.         }
  263.         else if (n == 4) {
  264.             if (size == 0) {
  265.                 system("cls");
  266.                 cout << "Ни один товар не находится в базе, попробуйте снова." << endl;
  267.             }
  268.             else {
  269.                 system("cls");
  270.                 cout << "Вывод всех товаров" << endl;
  271.                 cout << "--------------------------------------------------" << endl;
  272.                 for (int i = 0; i < size; i++) {
  273.                     cout << "\nНомер: " << storage[i].number << endl;
  274.                     cout << "Категория: " << storage[i].category << endl;
  275.                     cout << "Марка: " << storage[i].brand << endl;
  276.                     cout << "Цена оптовая: " << storage[i].OptPrice << endl;
  277.                     cout << "Цена розничная: " << storage[i].RozPrice << endl;
  278.                     cout << "Кол-во на складе: " << storage[i].count << endl;
  279.                 }
  280.             }
  281.             cout << endl;
  282.            
  283.         }
  284.         else {
  285.             break;
  286.         }
  287.  
  288.         DisplayCommands(MaxSizeStorage, size);
  289.         cin >> n;
  290.     }
  291.     _getch();
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement