Advertisement
onezee

1.0

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