Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <Windows.h>
- #include <fstream>
- #include <conio.h>
- using namespace std;
- struct Storage {
- int number;
- string category;
- string brand;
- float OptPrice;
- float RozPrice;
- int count;
- };
- void DisplayCommands(int MaxSize, int size) {
- cout << "Программа учета товаров на складе:" << endl;
- cout << " - расчитана на " << MaxSize << " товаров/товара/товар на складе." << endl;
- cout << " - в базе уже находится " << size << " товаров/товара/товар." << endl;
- cout << "\nСписок доступных команд:" << endl;
- cout << "--------------------------------------------------" << endl;
- cout << "1. Добавление товара в список." << endl;
- cout << "2. Изменить количество товара на складе." << endl;
- cout << "3. Вывод товара по заданной категории (номер, категория, марка)." << endl;
- cout << "4. Вывод всех товаров." << endl;
- cout << "5. Выход." << endl;
- }
- void main() {
- setlocale(LC_ALL, "Russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- const int MaxSizeStorage = 999;
- int MaxSize = MaxSizeStorage;
- Storage storage[MaxSizeStorage];
- int size = 0;
- int n, b;
- /*
- cout << "Выберите обязательное действие:" << endl;
- cout << "1. Загрузка базы данных из существующего файла." << endl;
- cout << "2. Создание новой базы данных." << endl;
- cin >> b;
- while (true) {
- if (b == 1) {
- string filename;
- string buffer;
- system("cls");
- cout << "Введите название базы данных (файла): ";
- cin >> filename;
- ifstream file(filename);
- if (!file.is_open()) {
- system("cls");
- cout << "Файл не найден, либо не правильный формат файла -> создание новой базы данных." << endl;
- break;
- }
- else {
- int i = 0, k = 0;
- for (file >> buffer; !file.eof(); file >> buffer) {
- cout << buffer << endl;
- }
- }
- }
- else if (b == 2) {
- }
- else {
- cout << "Некоректный ввод -> создание новой базы данных." << endl;
- break;
- }
- }
- */
- DisplayCommands(MaxSizeStorage, size);
- cin >> n;
- while (n != 5) {
- if (n == 1) {
- int number;
- string category;
- string brand;
- float OptPrice;
- float RozPrice;
- int count;
- size += 1;
- system("cls");
- cout << "Добавление товара в список. Шаг 1/6" << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите номер товара: ";
- cin >> number;
- storage[size - 1].number = number;
- system("cls");
- cout << "Добавление товара в список. Шаг 2/6: " << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите категорию товара: ";
- cin >> category;
- storage[size - 1].category = category;
- system("cls");
- cout << "Добавление товара в список. Шаг 3/6: " << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите марку товара: ";
- cin >> brand;
- storage[size - 1].brand = brand;
- system("cls");
- cout << "Добавление товара в список. Шаг 4/6: " << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите оптовую цену: ";
- cin >> OptPrice;
- storage[size - 1].OptPrice = OptPrice;
- system("cls");
- cout << "Добавление товара в список. Шаг 5/6: " << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите розничную цену: ";
- cin >> RozPrice;
- storage[size - 1].RozPrice = RozPrice;
- system("cls");
- cout << "Добавление товара в список. Шаг 6/6: " << endl;
- cout << "-------------------------------------------------" << endl;
- cout << "Введите кол-во на складе: ";
- cin >> count;
- storage[size - 1].count = count;
- system("cls");
- cout << "Товар успешно добавлен!\n" << endl;
- }
- else if (n == 2) {
- if (size == 0) {
- system("cls");
- cout << "Ни один товар не находится в базе, попробуйте снова.\n" << endl;
- }
- else {
- int number;
- bool check = false;
- system("cls");
- cout << "Введите номер товара, информацию которого хотите изменить: ";
- cin >> number;
- for (int i = 0; i < size; i++) {
- if (number == storage[i].number) {
- check = true;
- system("cls");
- cout << "Введите новое количество товара с номером - " << number << " : ";
- cin >> storage[i].count;
- }
- }
- if (check == false) {
- system("cls");
- cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
- }
- else {
- system("cls");
- cout << "Информация успешно изменена.\n" << endl;
- }
- }
- }
- else if (n == 3) {
- if (size == 0) {
- system("cls");
- cout << "Ни один товар не находится в базе, попробуйте снова.\n" << endl;
- }
- else {
- int m;
- bool check = false;
- system("cls");
- cout << "Укажите категорию для поиска:" << endl;
- cout << "1. По номеру товара." << endl;
- cout << "2. По категории товара." << endl;
- cout << "3. По марке товара." << endl;
- cin >> m;
- if (m == 1) {
- int number;
- system("cls");
- cout << "Введите номер товара для поиска: ";
- cin >> number;
- system("cls");
- for (int i = 0; i < size; i++) {
- if (number == storage[i].number) {
- check = true;
- cout << "Товар с номером - " << number << " найден. Его остальные данные:" << endl;
- cout << "Категория: " << storage[i].category << endl;
- cout << "Марка: " << storage[i].brand << endl;
- cout << "Цена оптовая: " << storage[i].OptPrice << endl;
- cout << "Цена розничная: " << storage[i].RozPrice << endl;
- cout << "Кол-во на складе: " << storage[i].count << endl;
- }
- }
- if (check == false) {
- system("cls");
- cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
- }
- }
- else if (m == 2) {
- string category;
- system("cls");
- cout << "Введите категорию товара для поиска: ";
- cin >> category;
- system("cls");
- for (int i = 0; i < size; i++) {
- if (category == storage[i].category) {
- check = true;
- cout << "Товар с категорией - " << category << " найден. Его остальные данные:" << endl;
- cout << "Номер: " << storage[i].number << endl;
- cout << "Марка: " << storage[i].brand << endl;
- cout << "Цена оптовая: " << storage[i].OptPrice << endl;
- cout << "Цена розничная: " << storage[i].RozPrice << endl;
- cout << "Кол-во на складе: " << storage[i].count << endl;
- }
- }
- if (check == false) {
- system("cls");
- cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
- }
- }
- else if (m == 3) {
- string brand;
- system("cls");
- cout << "Введите марку товара для поиска: ";
- cin >> brand;
- system("cls");
- for (int i = 0; i < size; i++) {
- if (brand == storage[i].brand) {
- check = true;
- cout << "Товар с маркой - " << brand << " найден. Его остальные данные:" << endl;
- cout << "Номер: " << storage[i].number << endl;
- cout << "Категория: " << storage[i].category << endl;
- cout << "Цена оптовая: " << storage[i].OptPrice << endl;
- cout << "Цена розничная: " << storage[i].RozPrice << endl;
- cout << "Кол-во на складе: " << storage[i].count << endl;
- }
- }
- if (check == false) {
- system("cls");
- cout << "Указанного товара не существует. Попробуйте еще раз.\n" << endl;
- }
- }
- else if (m != 1 && m != 2 && m != 3) {
- system("cls");
- cout << "Некорректный выбор данных для поиска. Попробуйте еще раз.\n" << endl;
- }
- else {
- cout << "\nПоиск выполнен." << endl;
- }
- cout << endl;
- }
- }
- else if (n == 4) {
- if (size == 0) {
- system("cls");
- cout << "Ни один товар не находится в базе, попробуйте снова." << endl;
- }
- else {
- system("cls");
- cout << "Вывод всех товаров" << endl;
- cout << "--------------------------------------------------" << endl;
- for (int i = 0; i < size; i++) {
- cout << "\nНомер: " << storage[i].number << endl;
- cout << "Категория: " << storage[i].category << endl;
- cout << "Марка: " << storage[i].brand << endl;
- cout << "Цена оптовая: " << storage[i].OptPrice << endl;
- cout << "Цена розничная: " << storage[i].RozPrice << endl;
- cout << "Кол-во на складе: " << storage[i].count << endl;
- }
- }
- cout << endl;
- }
- else {
- break;
- }
- DisplayCommands(MaxSizeStorage, size);
- cin >> n;
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement