Advertisement
kxcoze

satie__struct

May 4th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.15 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <string>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. struct {
  10.     string name;
  11.     string category;
  12.     string tovar;
  13.     float cost;
  14.     char bol;
  15. } mas[20];
  16. int n;
  17. string buff;// переменная, использующаяся в программе для очистки буфера
  18.  
  19. const int WIDHT = 12; // Ширина ячейки таблицы "Название таблицы"
  20. const int EDGE = 9; // Граница вывода строки
  21.  
  22. void list();
  23. void inputting();
  24. void search();
  25. void outputStr(const int, const int, string);
  26.  
  27. int main()
  28. {
  29.     SetConsoleCP(1251);
  30.     SetConsoleOutputCP(1251);
  31.     cout << "Введите количество товаров: ";
  32.     cin >> n;
  33.     system("CLS");
  34.     inputting();
  35.     list();
  36.     search();
  37.     return 0;
  38. }
  39.  
  40. void inputting() { // Процедура ввода данных
  41.     for (int i = 0; i < n; i++) {
  42.         system("CLS");
  43.         cout << " Введите данные для " << i + 1 << " записи :" << endl;
  44.         getline(cin, buff);
  45.  
  46.         cout << " Название товара - ";
  47.         getline(cin, mas[i].name);
  48.  
  49.         cout << " Категория товара (крупная, мелкая) - ";
  50.         getline(cin, mas[i].category);
  51.  
  52.         cout << " Цена товара - ";
  53.         cin >> mas[i].cost;
  54.         do {
  55.             cout << " Есть ли дополнительная гарнитура? (+,-): ";
  56.             char x = _getch();
  57.             if ((x == '+') || (x == '-'))
  58.             {
  59.                 cout << x << "\n";
  60.                 mas[i].bol = x;
  61.             }
  62.             else cout << "\r";
  63.         } while ((mas[i].bol != '+') && (mas[i].bol != '-'));
  64.  
  65.     }
  66. }
  67.  
  68.  
  69. void list()
  70. {
  71.     system("CLS");
  72.     cout << endl << endl << endl;
  73.     cout << "                Таблица: 'ПРАЙС ЛИСТ БЫТОВОЙ ТЕХНИКИ'  " << endl;
  74.     cout << "       ____________________________________________________________________" << endl;
  75.     cout << "      |   N   |  Hазвание   | Категория   |     Цена       |   Наличие     |" << endl;
  76.     cout << "      |  №пп  |  товара     |   товара    |    товара      |доп. гарнитуры |" << endl;
  77.     cout << "      |_______|_____________|_____________|________________|_______________|" << endl;
  78.     cout << "      |       |             |             |                |               |" << endl;
  79.     for (int i = 0; i < n; i++)
  80.     {
  81.         cout << "      | " << setw(3) << i + 1 << "   | ";
  82.         outputStr(EDGE - 1, WIDHT - 1, mas[i].name);
  83.         cout << " |  " << setw(7) << fixed << setprecision(2) << mas[i].category << "    |   " << setw(9) << setprecision(2) << mas[i].cost << "    |" << setw(8) << mas[i].bol << "       |" << endl;
  84.     }
  85.     cout << "      |_______|_____________|_____________|________________|_______________|" << endl << endl << endl;
  86. }
  87.  
  88. void search()
  89. {
  90.     int s;
  91.     getline(cin, buff); //очистка буфера
  92.     cout << " Введите значение, которое не должно превышать стоимость товара: ";
  93.     cin >> s;
  94.     system("CLS");
  95.     bool f = true;
  96.     cout << "\n\n Информация о товарах, стоимость которых не превышает " << s << "рублей:\n\n ";
  97.     for (int i = 0; i < n; i++)
  98.         if (mas[i].cost <= s)
  99.         {
  100.             cout << "   Название товара:        " << mas[i].name << endl;
  101.             cout << "   Категория товара        " << setprecision(2) << fixed << mas[i].category << endl;
  102.             cout << "   Цена товара:            " << setprecision(2) << fixed << mas[i].cost << endl;
  103.             cout << "   Наличие доп. гарнитуры: " << mas[i].bol << endl << endl;
  104.             f = false;
  105.         }
  106.     if (f) cout << "    Такого товара нет в наличии! Продолжить? " << endl;
  107.     system("pause>nul");
  108. }
  109.  
  110. // Вывод строки до определенного кол-ва символов, иначе вывести строку, далее заполнить пробелами до границы.
  111. void outputStr(const int x, const int w, string str) {
  112.     if (x > str.size()) {
  113.         cout << str;
  114.         int y = w - str.size();
  115.         while (y--)
  116.             cout << ' ';
  117.         return;
  118.     }
  119.     for (int i = 0; i < x; i++)
  120.         cout << str[i];
  121.     cout << "...";
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement