Advertisement
gasaichan

БДЗ

May 19th, 2017
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. /*
  2. Работает только с латинским вводом
  3. Дата вводится одной строкой дд мм гггг
  4. Выводится в нормальном формате дд.мм.гггг
  5. Проверка на валидность даты есть
  6. */
  7.  
  8. #include <iostream>
  9. #include <clocale>
  10. #include <Windows.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <stdlib.h>
  14.  
  15. using namespace std;
  16.  
  17. void structInit(struct price *pr, int n);
  18. void structOut(struct price *pr, int n);
  19. void structOutExp(struct price*, int n, int expDay, int expMonth, int expYear);
  20.  
  21. struct price {
  22.     char name[64];
  23.     int p;
  24.     int year;
  25.     int month;
  26.     int day;
  27. };
  28.  
  29. int main() {
  30.     setlocale(LC_ALL, "Russian");
  31.  
  32.     int n;
  33.  
  34.     cout << "Введите количество товаров: ";
  35.     cin >> n;
  36.  
  37.     struct price *pr = new price[n];
  38.     structInit(pr, n);
  39.  
  40.     cout << "****************************************************" << endl;
  41.  
  42.     cout << "Список товаров: " << endl;
  43.     structOut(pr, n);
  44.     cout << endl;
  45.  
  46.     cout << "****************************************************" << endl;
  47.  
  48.     int expDay, expMonth, expYear;
  49.  
  50.     cout << "Введите текущую дату (в формате день месяц год):";
  51.     cin >> expDay;
  52.     cin >> expMonth;
  53.     cin >> expYear;
  54.  
  55.     cout << "****************************************************" << endl;
  56.  
  57.     cout << "Товары, у которых истек срок годности: " << endl;
  58.     structOutExp(pr, n, expDay, expMonth, expYear);
  59.  
  60.     system("PAUSE");
  61. }
  62.  
  63. void structInit(struct price *pr, int n) {
  64.     for (int i = 0; i < n; i++) {
  65.         cout << "Товар № " << i + 1 << ": " << endl;
  66.         cout << "Введите название товара: ";
  67.         cin >> pr[i].name;
  68.         cout << "Введите цену товара: ";
  69.         cin >> pr[i].p;
  70.         cout << "Введите дату истечения срока годности у товара (в формате день месяц год) ";
  71.         cin >> pr[i].day;
  72.         cin >> pr[i].month;
  73.         cin >> pr[i].year;
  74.         while (pr[i].day > 31 && pr[i].month > 12) {
  75.             cout << "Invalid Data (>31 Days or >12 Months) " << endl;
  76.             cin >> pr[i].day;
  77.             cin >> pr[i].month;
  78.             cin >> pr[i].year;
  79.         }
  80.     }
  81. }
  82.  
  83. void structOut(struct price *pr, int n) {
  84.     for (int i = 0; i < n; i++) {
  85.         cout << "Товар № " << i + 1 << ": " << endl;
  86.         cout << "Название товара: " << pr[i].name << endl;
  87.         cout << "Цена: " << pr[i].p << endl;
  88.         cout << "Годен до: " << pr[i].day << "." << pr[i].month << "." << pr[i].year;
  89.         cout << endl;
  90.     }
  91. }
  92.  
  93. void structOutExp(struct price *pr, int n, int expDay, int expMonth, int expYear) {
  94.     for (int i = 0; i < n; i++) {
  95.         if ((pr[i].day <= expDay && pr[i].month <= expMonth && pr[i].year <= expYear) || (pr[i].month <= expMonth && pr[i].year <= expYear) || (pr[i].year < expYear)) {
  96.             cout << "Товар № " << i + 1 << ": " << endl;
  97.             cout << "Название товара: " << pr[i].name << endl;
  98.             cout << "Цена: " << pr[i].p << endl;
  99.             cout << "Годен до: " << pr[i].day << "." << pr[i].month << "." << pr[i].year << endl;
  100.             cout << endl;
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement