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
| #include <iostream>
#include <ctime>
#include <string>
using namespace std;
struct PRICE {
string Name, Shop, ID;
int Price;
int Quantity;
void Input() {
cout << "Enter Name of product: ";
cin >> Name;
cout << "Enter Shop name: ";
cin >> Shop;
cout << "Enter product ID: ";
cin >> ID;
cout << "Enter Price: ";
cin >> Price;
cout << "Enter Quantity of product: ";
cin >> Quantity;
cout << endl;
}
void Print() {
cout << "+---------+-----------------------------------------------" << endl;
cout << "|Name | " << Name << endl;
cout << "+---------+-----------------------------------------------" << endl;
cout << "|Shop | " << Shop << endl;
cout << "+---------+-----------------------------------------------" << endl;
cout << "|ID | " << ID << endl;
cout << "+---------+-----------------------------------------------" << endl;
cout << "|Price | " << Price << endl;
cout << "+---------+-----------------------------------------------" << endl;
cout << "|Quantity | " << Quantity << endl;
cout << "+---------+-----------------------------------------------" << endl << endl;
}
void Debug() {
string names[10] = { "Smartphone", "TV", "Laptop", "Model Y", "CyderTruck", "Spinner", "AMD Ryzen 5 3600", "Geistvo", "Uran", "WebCam" };
string shops[10] = { "AliExpress", "Deal", "Amazon", "Onliner", "Tesla", "MAZ", "SpaceX", "Socket", "kufar", "Avito" };
string IDs[10] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
Name = names[rand() % 10];
Shop = shops[rand() % 10];
ID = IDs[rand() % 10];
Price = rand() % 100;
Quantity = rand() % 100;
}
};
string* Arr_Exchange(string* arr, int& n) {
string* arr2 = new string[n + 1];
for (int i = 0; i < n; i++) { arr2[i] = arr[i]; }
return arr2;
}
int ID_Search(PRICE* arr, int n, string ID) {
for (int i = 0; i < n; i++) {
if (arr[i].ID == ID) { return i; }
}
return -1;
}
void Low_Output(PRICE* arr, int n) {
for (int i = 0; i < n; i++) {
if (arr[i].Quantity < 5) { arr[i].Print(); }
}
}
void Redact(PRICE* arr, int n, string ID) {
int i = ID_Search(arr, n, ID);
if (i != -1) { arr[i].Input(); }
else { cout << "Note not found :("; }
}
void Price_Sort(PRICE* arr, int n) {
for (int i = 0; i < n; i++) {
PRICE min = arr[i];
int min_i = i;
for (int j = i; j < n; j++) {
if (arr[j].Price < min.Price) { min = arr[j]; min_i = j; }
}
PRICE c = arr[i];
arr[i] = min;
arr[min_i] = c;
}
for (int i = 0; i < n; i++) { arr[i].Print(); }
}
bool Search(string* arr, int n, string s) {
for (int i = 0; i < n; i++) {
if (arr[i] == s) { return true; }
}
return false;
}
void Shops_Print(PRICE* arr, int n) {
int len = 0, q = 0, count = 0;
string list[100];
for (int i = 0; i < n; i++) {
while (i < n && Search(list, len, arr[i].Shop)) { i++; }
if (i == n) { break; }
list[q] = arr[i].Shop;
q++;
len++;
for (int j = 0; j < n; j++) {
if (arr[j].Shop == arr[i].Shop) { arr[j].Print(); count++; }
}
}
}
int main() {
srand(time(NULL));
int n;
cin >> n;
PRICE* arr = new PRICE[n];
for (int i = 0; i < n; i++) { arr[i].Debug(); arr[i].Print(); }
cout << endl << endl << endl;
Shops_Print(arr, n);
} |