1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
class GoodsItem
{
public:
std::string name, manufacture;
struct date
{
int day;
int month;
int year;
}d;
std::string price;
friend bool operator < (const GoodsItem &item1, const GoodsItem &item2);
};
std::ostream& operator << (std::ostream &out, const GoodsItem &value);
std::ostream &operator << (std::ostream &out, const std::vector<GoodsItem>& value);
void input(std::vector<GoodsItem>& store, const int &amount);
void printSelected(std::vector<GoodsItem>& store, const std::string& price);
int main(int argc, char *argv[])
{
bool running(true);
std::vector<GoodsItem> store;
while (running)
{
int caseInput;
std::string price;
std::cout << "\nViberite deistvie:\n"
<< "1.Vvod\n"
<< "2.Vivod\n"
<< "3.Vivod po cene\n"
<< "4.vihod\n\n";
(std::cin >> caseInput).get();
switch (caseInput)
{
case 1:
int amount;
std::cout << "Vvedite kol-vo zapisey: ";
(std::cin >> amount).get();
input(store, amount);
std::sort(store.begin(), store.end());
break;
case 2:
std::cout << store;
break;
case 3:
std::cout << "Gotovnost: ";
std::getline(std::cin, price);
printSelected(store, price);
break;
default:
running = false;
}
}
return EXIT_SUCCESS;
}
std::ostream& operator << (std::ostream &out, const GoodsItem &value)
{
out << " Nazvanie izdeliya: " << value.name << std::endl
<< " marka izdeliya: " << value.manufacture << std::endl
<< " den priema v remont: " << value.d.day << std::endl
<< " mesyac priema v remont: " << value.d.month << std::endl
<< " god priema v remont: " << value.d.year << std::endl
<< " Gotovnost: " << value.price << std::endl
<< std::endl;
return out;
}
std::ostream &operator << (std::ostream &out, const std::vector<GoodsItem>& value)
{
out << "Perechen izdeliy:" << std::endl;
for (int i = 0; i < value.size(); ++i)
out << value[i];
return out;
}
bool operator < (const GoodsItem &item1, const GoodsItem &item2)
{
return item1.price < item2.price;
}
void input(std::vector<GoodsItem>& store, const int &amount)
{
for (int i = 0; i < amount; ++i) {
GoodsItem item;
std::cout << "Vvedite Nazvanie izdeliya: ";
std::cin >> item.name;
std::cout << "Vvedite marky izdeliya: ";
std::cin >> item.manufacture;
std::cout << "Vvedite den priema v remont: ";
std::cin >> item.d.day;
std::cout << "Vvedite mecyac priema v remont: ";
std::cin >> item.d.month;
std::cout << "Vvedite god priema v remont: ";
(std::cin >> item.d.year).get();
std::cout << "Vvedite sostoyanie zakaza: ";
std::getline(std::cin, item.price);
store.push_back(item);
}
}
void printSelected(std::vector<GoodsItem>& store, const std::string &price)
{
std::vector<GoodsItem>::iterator item = store.end();
for (std::vector<GoodsItem>::iterator it = store.begin(); it != store.end(); ++it)
if (price == it->price) item = it;
if (item == store.end())
{
std::cout << "Zakaz Gotov " << price << " Ne gotov" << std::endl;
}
else std::cout << (*item) << std::endl;
} |