Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <locale.h>
  5. #include <string.h>
  6. #include <windows.h>
  7. #include <stdlib.h>
  8. #include <io.h>
  9. #include <stdlib.h>
  10. #include <process.h>
  11. #include <iostream>
  12.  
  13.  
  14. struct Item {
  15.     std::string name;
  16.     int price;
  17.     int amount;
  18.     int date; // если дата - это только год
  19. };
  20.  
  21.  
  22. //Item* Add(string name, int price, int amount, int date) {
  23.  
  24. //    Item* it;
  25.  
  26. //
  27.  
  28. //}
  29.  
  30.  
  31. Item* Add() {
  32.     Item* it = new Item;
  33.     std::string title;
  34.     std::cin >> title;
  35.     it->name = title;
  36.     int pr;
  37.     std::cin >> pr;
  38.     it->price = pr;
  39.     int amnt;
  40.     std::cin >> amnt;
  41.     it->amount = amnt;
  42.     int d;
  43.     std::cin >> d;
  44.     it->date = d;
  45.     return it;
  46. }
  47.  
  48.  
  49. void Output(Item* items, int n) {
  50.     for (int i = 0; i < n; ++i) {
  51.         std::cout << items[i].name << ' '<< items[i].price << ' '<< items[i].amount << ' '<< items[i].date << endl;
  52.     }
  53. }
  54.  
  55.  
  56. void DateSearch(Item* items, int n, int year) {
  57.     for (int i = 0; i < n; ++i) {
  58.         if (items[i].date >= year) {
  59.             std::cout << items[i].name << endl;
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. int MaxPrice(Item* items, int n) {
  66.     int max_price = items[0].price;
  67.     for (int i = 0; i < n; ++i) {
  68.         if (items[i].price >= max_price) {
  69.             max_price = items[i].price;
  70.         }
  71.     }
  72.     return max_price;
  73. }
  74.  
  75.  
  76. int AmountSearch(Item* items, int n, int count) {
  77.     int items_sum = 0;
  78.     for (int i = 0; i < n; ++i) {
  79.         if (items[i].amount >= count) {
  80.             std::cout << items[i].name << ' ' << items[i].date << endl;
  81.             items_sum += items[i].price * items[i].amount;
  82.         }
  83.     }
  84.     return items_sum;
  85. }
  86.  
  87. int main() {
  88.     setlocale(0,"russian");
  89.     Item *item = new Item [10];
  90.     int n=0;
  91.     int count = 0;
  92.     long number;
  93.     char nm[50];
  94.     int choice;
  95.     int year;
  96.     do{
  97.         printf("\nВыберите действие:\n 1)Записать данные в массив структур\n 2)Вывод массива структур\n 3)Поиск по дате\n 4)Поиск наибольшей стоимости\n 5)Поиск дат поступления и наименования товаров, объемов партий которых не меньше заданного значения\n 6)Выйти\n\n");
  98.         scanf("%d",&choice);
  99.         switch(choice)
  100.         {
  101.         case 1:
  102.             Add();
  103.             break;
  104.         case 2:
  105.             Output(item,n);
  106.             break;
  107.         case 3:
  108.             std::cin >> year;
  109.             DateSearch(item,n,year);
  110.             break;
  111.         case 4:
  112.             MaxPrice(item,n);
  113.             break;
  114.         case 5:
  115.             std::cin >> count;
  116.             AmountSearch(item,n, count);
  117.             break;
  118.         case 6:
  119.             return 0;
  120.         default:
  121.             puts("Нет такого действия!");
  122.         }
  123.     }
  124.     while (choice!=6);
  125.     delete [] item;
  126.     getchar();
  127.     getchar();
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement