Advertisement
onezee

Console1.1

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