-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask1.cpp
326 lines (313 loc) · 8.67 KB
/
Task1.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#define M 40
#define horse 500
#define saber 100
#define rubie 50
#define necklace 10
#define wife 200
#include <iostream>
#include <string>
#include <fstream>
#include <io.h>
#include <algorithm>
#include <fcntl.h>
#include <locale>
#include <locale.h>
#include <Windows.h>
#include <fstream>
#include <iterator>
#include <stdlib.h>
#include <math.h>
#include <codecvt>
using namespace std;
struct rubber {
string name;
int alive;
int horses = 0;
int sabers = 0;
int rubies = 0;
int necklaces = 0;
int wifes = 0;
int coins = 0;
int wealth = 0;
};
void head() {
cout << "------------------------------------------------------------------------------------------\n";
cout << "| Имя | Живой | Имущество | Богатство |\n";
cout << "| | |----------------------------------------------------------| |\n";
cout << "| | | Скакуны | Сабли | Рубины | Ожерелья | Жены | Монеты |-----------|\n";
cout << "------------------------------------------------------------------------------------------\n";
}
std::wstring StringToWString(const std::string& s)
{
std::wstring temp(s.length(), L' ');
std::copy(s.begin(), s.end(), temp.begin());
return temp;
}
void write_rub(rubber r) {
cout << "|";
cout.width(9);
cout << r.name;
cout.width(1);
cout << "|";
cout.width(7);
cout << r.alive;
cout.width(1);
cout << "|";
cout.width(9);
cout << r.horses;
cout.width(1);
cout << "|";
cout.width(9);
cout << r.sabers;
cout.width(1);
cout << "|";
cout.width(8);
cout << r.rubies;
cout.width(1);
cout << "|";
cout.width(12);
cout << r.necklaces;
cout.width(1);
cout << "|";
cout.width(7);
cout << r.wifes;
cout.width(1);
cout << "|";
cout.width(8);
cout << r.coins;
cout.width(1);
cout << "|";
cout.width(11);
cout << r.wealth;
cout.width(1);
cout << "|\n";
}
int set_wealth(rubber r) {
return r.coins + r.horses * horse + r.sabers * saber + r.rubies * rubie + r.necklaces * necklace - r.wifes * wife;
}
int add(int a, int b) {
return a + b;
}
rubber read(rubber rubbers[], string filename, rubber itogo) {
srand(unsigned(std::time(0)));
string name;
int crew = 0;
while (crew < M)
{
rubbers[crew].alive = 1;
rubbers[crew].horses = rand() % 10;
rubbers[crew].coins = rand() % 5000;
rubbers[crew].necklaces = rand() % 10;
rubbers[crew].rubies = rand() % 50;
rubbers[crew].sabers = rand() % 5;
rubbers[crew].wifes = rand() % 10;
rubbers[crew].wealth = set_wealth(rubbers[crew]);
if (rubbers[crew].alive) {
itogo.alive++;
itogo.horses += rubbers[crew].horses;
itogo.coins += rubbers[crew].coins;
itogo.necklaces += rubbers[crew].necklaces;
itogo.rubies += rubbers[crew].rubies;
itogo.sabers += rubbers[crew].sabers;
itogo.wifes += rubbers[crew].wifes;
itogo.wealth = set_wealth(itogo);
}
crew++;
}
string line; int i = 0;
ifstream in(filename);
for(i=0;i<M;i++){
in >> line;
rubbers[i].name =line;
}
in.close();
itogo.name = "Итого";
return itogo;
}
void menu() {
cout << "1 - Вся таблица" << "\n";
cout << "2 - Вывод живых" << "\n";
cout << "3 - Самый богатый" << "\n";
cout << "4 - Убить" << "\n";
cout << "5 - Новый член" << "\n";
cout << "6 - Вывод по имени" << "\n";
cout << "7 - Диаграмма" << "\n";
cout << "0 - Выход" << "\n";
}
void write(rubber rubbers[], rubber itogo, int crew) {
head();
int i = 0;
while (i < crew) {
write_rub(rubbers[i]);
i++;
}
write_rub(itogo);
}
void write_alive(rubber rubbers[], rubber itogo, int crew) {
head();
int i = 0;
while (i < crew) {
if (rubbers[i].alive) write_rub(rubbers[i]);
i++;
}
write_rub(itogo);
}
void the_most_rich(rubber rubbers[], int crew) {
int i = 0;
int max = 0;
for (i = 0; i < crew; i++) {
if (rubbers[i].wealth > max&& rubbers[i].alive) max = rubbers[i].wealth;
}
head();
for (i = 0; i < crew; i++) {
if (rubbers[i].wealth == max && rubbers[i].alive) write_rub(rubbers[i]);
}
}
rubber kill(rubber rubbers[], rubber itogo, int crew) {
cout.imbue(locale(".1251"));
cin.imbue(locale(".866"));
cout << "Введите имя убитого:\n";
string name;
cin >> name;
int i = -1;
int t = 0;
while (i < crew && t == 0) {
i++;
if (rubbers[i].name == name && rubbers[i].alive) {
rubbers[i].alive = 0;
t = 1;
}
}
rubbers[i].alive = 0;
itogo.alive--;
itogo.horses -= rubbers[i].horses;
itogo.coins -= rubbers[i].coins;
itogo.necklaces -= rubbers[i].necklaces;
itogo.rubies -= rubbers[i].rubies;
itogo.sabers -= rubbers[i].sabers;
itogo.wifes -= rubbers[i].wifes;
itogo.wealth = set_wealth(itogo);
return itogo;
}
rubber freshman(rubber rubbers[], rubber itogo, int crew) {
wcout.imbue(locale(".1251"));
wcin.imbue(locale(".866"));
cout << "Введите имя:\n";
string name;
cin >> name;
rubbers[crew].name = name;
cout << "Жив:\n";
cin >> rubbers[crew].alive;
cout << "Скакуны:\n";
cin >> rubbers[crew].horses;
cout << "Сабли:\n";
cin >> rubbers[crew].sabers;
cout << "Рубины:\n";
cin >> rubbers[crew].rubies;
cout << "Ожерелья:\n";
cin >> rubbers[crew].necklaces;
cout << "Жены:\n";
cin >> rubbers[crew].wifes;
cout << "Монеты:\n";
cin >> rubbers[crew].coins;
rubbers[crew].wealth =
set_wealth(rubbers[crew]);
if (rubbers[crew].alive) {
itogo.alive++;
itogo.horses += rubbers[crew].horses;
itogo.coins += rubbers[crew].coins;
itogo.necklaces += rubbers[crew].necklaces;
itogo.rubies += rubbers[crew].rubies;
itogo.sabers += rubbers[crew].sabers;
itogo.wifes += rubbers[crew].wifes;
itogo.wealth = set_wealth(itogo);
}
return itogo;
}
void findname(rubber rubbers[], int crew) {
cout.imbue(locale(".1251"));
cin.imbue(locale(".866"));
string name;
cout << "Введи имя:" << endl;
cin >> name;
cout << "Вы ищете: ";
cout << name;
cout << name << "\n";
head();
for (int i = 0; i < crew; i++) {
if (name == rubbers[i].name) write_rub(rubbers[i]);
}
}
void graph(rubber rubbers[], int crew) {
for (int i = 0; i < 99; i++) {
printf("\n");
}
int len = 1800;
int div = 15;
int width = 650;
cout << "\n";
for (int i = 0; i < crew; i++) {
wcout.width((len / crew) / div);
if (rubbers[i].alive) cout << rubbers[i].name;
}
cout << "\n";
float x;
HDC hDC = GetDC(GetConsoleWindow());
HPEN Pen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
SelectObject(hDC, Pen);
MoveToEx(hDC, 6, 0, NULL);
LineTo(hDC, 6, len);
MoveToEx(hDC, 0, width, NULL);
LineTo(hDC, len, width);
int l = crew;
for (int i = 0; i < crew; i++) {
if (rubbers[i].alive) {
MoveToEx(hDC, 6 + i * (len / crew), width - rubbers[i].wealth / div, NULL);
LineTo(hDC, 6 + i * (len / crew), width);
MoveToEx(hDC, 6 + i * (len / crew), width - rubbers[i].wealth / div, NULL);
LineTo(hDC, 6 + (i + 1) * (len / crew), width - rubbers[i].wealth / div);
MoveToEx(hDC, 6 + (i + 1) * (len / crew), width - rubbers[i].wealth / div, NULL);
LineTo(hDC, 6 + (i + 1) * (len / crew), width);
}
}
system("pause");
}
int crew = M;
rubber rubbers[40];
rubber itogo;
int main()
{
setlocale(0, "");
itogo = read(rubbers, "names.txt", itogo);
menu();
int i;
cin >> i;
while (i != 0) {
switch (i) {
case(1):
write(rubbers, itogo, crew);
break;
case(2):
write_alive(rubbers, itogo, crew);
break;
case(3):
the_most_rich(rubbers, crew);
break;
case(4):
itogo = kill(rubbers, itogo, crew);
break;
case(5):
itogo = freshman(rubbers, itogo, crew);
crew++;
break;
case(6):
findname(rubbers, crew);
break;
case(7):
graph(rubbers, crew);
break;
}
menu();
cin >> i;
}
}