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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
| #include <iostream>
#include <ctime>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <regex>
using namespace std;
class Changer {
public:
void set_date(string changer_date)
{
dates.push_back(changer_date);
/*date = changer_date;*/
}
string get_date()
{
return dates[1];
}
void set_valuta(string changer_valuta)
{
valutas.push_back(changer_valuta);
/*valuta = changer_valuta;*/
}
string get_valuta()
{
return valuta;
}
void set_currency(double changer_currency)
{
currencys.push_back(changer_currency);
/*currency = changer_currency;*/
}
double get_currency()
{
return currency;
}
void set_rubles(double changer_rubles)
{
rubless.push_back(changer_rubles);
}
int check_valuta()
{
if (valuta != "AUD" && valuta != "AZN" && valuta != "ALL" && valuta != "DZD" && valuta != "AOA" && valuta != "ARS" && valuta != "AMD"
&& valuta != "AWG" && valuta != "AFN" && valuta != "BSD" && valuta != "BDT" && valuta != "BBD" && valuta != "DHD" && valuta != "BZD"
&& valuta != "BYR" && valuta != "BGN" && valuta != "BOB" && valuta != "BWP" && valuta != "BRL" && valuta != "BND" && valuta != "BIF"
&& valuta != "BTN" && valuta != "VUV" && valuta != "HUF" && valuta != "VEF" && valuta != "XCD" && valuta != "VND" && valuta != "HTG"
&& valuta != "GYD" && valuta != "GMD" && valuta != "GHS" && valuta != "GTQ" && valuta != "GNF" && valuta != "GIP" && valuta != "HNL"
&& valuta != "HKD" && valuta != "GEL" && valuta != "ANG" && valuta != "DKK" && valuta != "DJF" && valuta != "AED" && valuta != "STD"
&& valuta != "KYD" && valuta != "SBD" && valuta != "USD" && valuta != "FJD" && valuta != "DOP" && valuta != "EUR" && valuta != "EGP"
&& valuta != "ZMK" && valuta != "ILS" && valuta != "INR" && valuta != "IDR" && valuta != "JOD" && valuta != "IQD" && valuta != "IRR"
&& valuta != "ISK" && valuta != "YER" && valuta != "KZT" && valuta != "KHR" && valuta != "CAD" && valuta != "QAR" && valuta != "KES"
&& valuta != "PGK" && valuta != "KGS" && valuta != "CNY" && valuta != "COP" && valuta != "KMF" && valuta != "BAM" && valuta != "CDF"
&& valuta != "CRC" && valuta != "CUP" && valuta != "KWD" && valuta != "MMK" && valuta != "LAK" && valuta != "LVL" && valuta != "CUP"
&& valuta != "KWD" && valuta != "MMK" && valuta != "LAK" && valuta != "LVL" && valuta != "LRD" && valuta != "LBP" && valuta != "LYD"
&& valuta != "LTL" && valuta != "LSL" && valuta != "MUR" && valuta != "MRO" && valuta != "MKD" && valuta != "MWK" && valuta != "MGA"
&& valuta != "MYR" && valuta != "MVR" && valuta != "MAD" && valuta != "MXN" && valuta != "MZN" && valuta != "MDL" && valuta != "MNT"
&& valuta != "NAD" && valuta != "NPR" && valuta != "NGN" && valuta != "NIO" && valuta != "NZD" && valuta != "NOK" && valuta != "OMR"
&& valuta != "PKR" && valuta != "PAB" && valuta != "MOP" && valuta != "PYG" && valuta != "PEN" && valuta != "PLN" && valuta != "PRB"
&& valuta != "RWF" && valuta != "RON" && valuta != "SVC" && valuta != "WST" && valuta != "SAR" && valuta != "SZL" && valuta != "KPW"
&& valuta != "SCR" && valuta != "RSD" && valuta != "SGD" && valuta != "SYP" && valuta != "SOS" && valuta != "SDG" && valuta != "SRD"
&& valuta != "SLL" && valuta != "TJS" && valuta != "THB" && valuta != "TWD" && valuta != "TZS" && valuta != "TOP" && valuta != "TND"
&& valuta != "TRY" && valuta != "TMT" && valuta != "UGX" && valuta != "UZS" && valuta != "UAH" && valuta != "UYU" && valuta != "FOK"
&& valuta != "PHP" && valuta != "XAF" && valuta != "XOF" && valuta != "XPF" && valuta != "GGP" && valuta != "JEP" && valuta != "GBP"
&& valuta != "FKP" && valuta != "HRK" && valuta != "CZK" && valuta != "CLP" && valuta != "SEK" && valuta != "CHF" && valuta != "LKR"
&& valuta != "CVE" && valuta != "ERN" && valuta != "EEK" && valuta != "ETB" && valuta != "ZAR" && valuta != "KRW" && valuta != "JMD"
&& valuta != "TTD" && valuta != "JPY" && valuta != "RUB")
return 0;
else
return 1;
}
double get_convert()
{
return convert;
}
void set_convert()
{
if (valuta == "RUB")
currency = 1;
convert = rubles / currency;
converts.push_back(convert);
}
int check_date()
{
if (regex_match(date, rx) == false)
{
checker = 0;
}
else
checker = 1;
return checker;
}
friend ostream& operator<< (std::ostream& out, const Changer& change);
friend istream& operator>> (std::istream& in, Changer& change);
private:
/*int d;
int month;*/
string date;
string valuta;
double currency;
double rubles;
int checker;
double convert;
regex rx{ R"((0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012]))" };
vector <string> dates;
vector <string> valutas;
vector <double> currencys;
vector <double> rubless;
vector <double> converts;
};
ostream& operator<< (std::ostream& out, const Changer& change)
{
int i = 0;
while (change.dates.size() != 0)
{
out << change.dates[i] << endl;
return out;
i++;
}
}
istream& operator>> (std::istream& in, Changer& change)
{
cout << "Date >";
in >> change.date;
if (change.check_date() == 0)
{
cout << "Incorrect date\n";
while (change.check_date() == 0)
{
cout << "Enter date > ";
while (!(in >> change.date) || (in.peek() != '\n'))//пока не будет введено нормальное число, выполняем цикл
{
cin.clear();
while (cin.get() != '\n');
std::cout << "Error!\n" << "Try again.Enter valuta > ";
}
change.check_date();
}
}
cout << "Valuta >";
in >> change.valuta;
transform(change.valuta.begin(), change.valuta.end(), change.valuta.begin(), ::toupper);
if (change.check_valuta() == 0)
{
cout << "Incorrect valuta\n";
while (change.check_valuta() == 0)
{
cout << "Enter valuta > ";
while (!(in >> change.valuta) || (in.peek() != '\n'))//пока не будет введено нормальное число, выполняем цикл
{
in.clear();
while (in.get() != '\n');
std::cout << "Error!\n" << "Try again.Enter valuta > ";
}
transform(change.valuta.begin(), change.valuta.end(), change.valuta.begin(), ::toupper);
change.check_valuta();
}
}
cout << "Currency >";
while (!(in >> change.currency) || (in.peek() != '\n') | (change.currency <= 0))//пока не будет введено нормальное число, выполняем цикл
{
in.clear();
while (in.get() != '\n');
cout << "Error!\n" << "Try again.Enter currency > ";
}
cout << "Rubles >";
while (!(in >> change.rubles) || (in.peek() != '\n') || (change.rubles < 0))//пока не будет введено нормальное число, выполняем цикл
{
in.clear();
while (in.get() != '\n');
std::cout << "Error!\n" << "Try again.Enter rubles > ";
}
return in;
}
int check_chooser(int chooser) //проверка на введеное значение x;
{
int wish = 2;
while (wish == 2)
{
if (!cin) //если произошла ошибка ввода, то !cin вернёт true
{
while (!(cin >> chooser) || (cin.peek() != '\n'))//пока не будет введено нормальное число, выполняем цикл
{
cin.clear();
while (cin.get() != '\n');
std::cout << "Enter 1/2 > ";
}
}
else
{
cout << "Enter 1/2 > ";
while (!(cin >> chooser) || (cin.peek() != '\n'))//пока не будет введено нормальное число, выполняем цикл
{
cin.clear();
while (cin.get() != '\n');
std::cout << "Enter 1/2 > ";
}
}
if (chooser == 1 || chooser == 2)
wish = 0;
}
return chooser;
}
bool check_wish(bool wish)
{
string no;//переменная,отвечающая за продолжение
do
{
if (no == "y" || no == "yes")
{
wish = true;
}
cout << "Continue? (Y/N)>";
while (!(cin >> no) || (cin.peek() != '\n')) //цикл,отвечающий за проверку вводимых типов данных
{
cin.clear();
while (cin.get() != '\n');
std::cout << "Continue? (Y/N) > ";
}
transform(no.begin(), no.end(), no.begin(), ::tolower); // понимжение регистра
} while (no != "n" && no != "no" && no != "y" && no != "yes");
if (no == "n" || no == "no")
{
wish = false;
}
return wish;
}
void filler(string &date, string &valuta, double ¤cy, double&rubles,Changer change,vector<string> &dates,vector <string> &valutas,vector<double>& currencys,vector<double>& rubless)
{
ifstream filein("input.txt");
while (filein)
{
filein >> date >> valuta >> currency >> rubles;
dates.push_back(date);
valutas.push_back(valuta);
currencys.push_back(currency);
rubless.push_back(rubles);
/*change.set_date(date);
transform(valuta.begin(), valuta.end(), valuta.begin(), ::toupper);
change.set_valuta(valuta);
change.set_currency(currency);
change.set_rubles(rubles);*/
}
/*cout << change.get_date();*/
//change.set_date(date);
///*change.check_date();
//if (change.check_date() == 0)
// cout << "\nIncorrect date";*/
//transform(valuta.begin(), valuta.end(), valuta.begin(), ::toupper);
//change.set_valuta(valuta);
///*change.check_valuta();
//if (change.check_valuta() == 0)
// cout << "\nIncorrect valuta";*/
//change.set_currency(currency);
////if (currency == 0)
//// /*throw runtime_error("Currency = 0 or incorrect currency");*/
//// cout << "Currency = 0 or incorrect currency";
//change.set_rubles(rubles);
///*if (rubles == 0)
// cout << "\nRubles = 0 or incorrect rubles";*/
}
int main() {
//ifstream - файловый ввод ;ofstream - файловый вывод
Changer change;
/*int day;*/
string date;
/*int month;*/
double rubles = 0;
string valuta;
double currency = 0;
vector <string> dates;
vector <string> valutas;
vector <double> currencys;
vector <double> rubless;
vector <double> converts;
ifstream filein;
ofstream fileout;
bool wish = true;
while (wish)
{
cout << "How you want to enter data:\n1)Keyboard\n2)From a file\nChoose the one >";
int chooser;
cin >> chooser;
cout << endl;
if (chooser != 1 && chooser != 2)
{
chooser = check_chooser(chooser);
}
if (chooser == 1)
{
cin >> change;
}
else
{
filein.open("input.txt");
if (!filein.is_open())
{
cout << "Error! Input cant be open";
}
else
{
filler(date, valuta, currency, rubles,change,dates,valutas,currencys,rubless);
for (int i = 0; i < dates.size(); ++i)
{
change.set_date(dates[i]);
change.set_valuta(valutas[i]);
change.set_currency(currencys[i]);
change.set_rubles(rubless[i]);
}
if (rubles == 0 || currency == 0 || change.check_date() == 0 || change.check_valuta() == 0)
{
cout << "\nThe program will not continue to work further.Incorrect data\n";
return 0;
}
}
filein.close();
}
cout << "How do you want to output data:\n1)To the console\n2)To a file\nChoose the one > ";
int outputer;
cin >> outputer;
if (outputer != 1 && outputer != 2)
{
outputer = check_chooser(outputer);
}
if (outputer == 1)
{
change.set_convert();
cout << change;
}
else
{
fileout.open("output.txt");
if (!fileout.is_open())
{
cout << "Error! Output cant be open";
}
else
{
change.set_convert();
fileout << change;
}
fileout.close();
}
cout << endl;
wish = check_wish(wish);
cout << endl;
}
return 0;
} |