Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <iomanip>
- #include <iostream>
- #include <string>
- #include <windows.h>
- using namespace std;
- struct {
- string name;
- string category;
- string tovar;
- float cost;
- char bol;
- } mas[20];
- int n;
- string buff;// переменная, использующаяся в программе для очистки буфера
- const int WIDHT = 12; // Ширина ячейки таблицы "Название таблицы"
- const int EDGE = 9; // Граница вывода строки
- void list();
- void inputting();
- void search();
- void outputStr(const int, const int, string);
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "Введите количество товаров: ";
- cin >> n;
- system("CLS");
- inputting();
- list();
- search();
- return 0;
- }
- void inputting() { // Процедура ввода данных
- for (int i = 0; i < n; i++) {
- system("CLS");
- cout << " Введите данные для " << i + 1 << " записи :" << endl;
- getline(cin, buff);
- cout << " Название товара - ";
- getline(cin, mas[i].name);
- cout << " Категория товара (крупная, мелкая) - ";
- getline(cin, mas[i].category);
- cout << " Цена товара - ";
- cin >> mas[i].cost;
- do {
- cout << " Есть ли дополнительная гарнитура? (+,-): ";
- char x = _getch();
- if ((x == '+') || (x == '-'))
- {
- cout << x << "\n";
- mas[i].bol = x;
- }
- else cout << "\r";
- } while ((mas[i].bol != '+') && (mas[i].bol != '-'));
- }
- }
- void list()
- {
- system("CLS");
- cout << endl << endl << endl;
- cout << " Таблица: 'ПРАЙС ЛИСТ БЫТОВОЙ ТЕХНИКИ' " << endl;
- cout << " ____________________________________________________________________" << endl;
- cout << " | N | Hазвание | Категория | Цена | Наличие |" << endl;
- cout << " | №пп | товара | товара | товара |доп. гарнитуры |" << endl;
- cout << " |_______|_____________|_____________|________________|_______________|" << endl;
- cout << " | | | | | |" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << " | " << setw(3) << i + 1 << " | ";
- outputStr(EDGE - 1, WIDHT - 1, mas[i].name);
- cout << " | " << setw(7) << fixed << setprecision(2) << mas[i].category << " | " << setw(9) << setprecision(2) << mas[i].cost << " |" << setw(8) << mas[i].bol << " |" << endl;
- }
- cout << " |_______|_____________|_____________|________________|_______________|" << endl << endl << endl;
- }
- void search()
- {
- int s;
- getline(cin, buff); //очистка буфера
- cout << " Введите значение, которое не должно превышать стоимость товара: ";
- cin >> s;
- system("CLS");
- bool f = true;
- cout << "\n\n Информация о товарах, стоимость которых не превышает " << s << "рублей:\n\n ";
- for (int i = 0; i < n; i++)
- if (mas[i].cost <= s)
- {
- cout << " Название товара: " << mas[i].name << endl;
- cout << " Категория товара " << setprecision(2) << fixed << mas[i].category << endl;
- cout << " Цена товара: " << setprecision(2) << fixed << mas[i].cost << endl;
- cout << " Наличие доп. гарнитуры: " << mas[i].bol << endl << endl;
- f = false;
- }
- if (f) cout << " Такого товара нет в наличии! Продолжить? " << endl;
- system("pause>nul");
- }
- // Вывод строки до определенного кол-ва символов, иначе вывести строку, далее заполнить пробелами до границы.
- void outputStr(const int x, const int w, string str) {
- if (x > str.size()) {
- cout << str;
- int y = w - str.size();
- while (y--)
- cout << ' ';
- return;
- }
- for (int i = 0; i < x; i++)
- cout << str[i];
- cout << "...";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement