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
| struct match
{
string comand1;
string comand2;
int count1;
int count2;
int won1, won2;
int lose1, lose2;
int result1, result2;
int games1, games2;
int miss1, miss2;
int subcount1, subcount2;
int tie1, tie2;
};
char Check(char _choice)
{
if (_choice != 'y' && _choice != 'n') // если ввел не y и не n
{
cout << "Введите y или n, пожалуйста (y/n) ";
cin >> _choice;
}
return _choice;
}
match Sorting(match _Match)
{
_Match.games1 += 1;
_Match.games2 += 1;
if (_Match.count1 > _Match.count2)
{
_Match.won1 += 1;
_Match.lose2 += 1;
_Match.result1 += 3;
_Match.result2 += 1;
_Match.miss2 += _Match.count1;
_Match.miss1 += _Match.count2;
}
else if (_Match.count1 < _Match.count2)
{
_Match.won2 += 1;
_Match.lose1 += 1;
_Match.result2 += 3;
_Match.result1 += 1;
_Match.miss1 += _Match.count2;
_Match.miss2 += _Match.count1;
}
else if (_Match.count1 = _Match.count2)
{
_Match.result1 += 2;
_Match.result2 += 2;
_Match.tie1 += 1;
_Match.tie2 += 1;
_Match.miss1 += _Match.count2;
_Match.miss2 += _Match.count1;
}
_Match.subcount1 = _Match.count1 - _Match.miss1;
_Match.subcount2 = _Match.count2 - _Match.miss2;
if (_Match.subcount1 < 0 || _Match.subcount2 < 0)
{
_Match.subcount1 = 0;
_Match.subcount2 = 0;
}
return _Match;
}
int main()
{
setlocale(LC_ALL, "Russian");
vector <match> matches;
vector<match_comand> _matches;
char choice;
char *buffer = new char[20];
cout << "Хотите ввести результаты нового матча? (нажмите в английской раскладке y, если да, или n, если нет, и Enter) ";
cin >> choice;
choice = Check(choice);
while (choice != 'n')
{
match Match;
match_comand MatchRes;
Match.won1 = 0, Match.won2 = 0;
Match.lose1 = 0, Match.lose2 = 0;
Match.games1 = 0, Match.games2 = 0;
Match.miss1 = 0, Match.miss2 = 0;
Match.subcount1 = 0, Match.subcount2 = 0;
Match.tie1 = 0, Match.tie2 = 0;
Match.result1 = 0, Match.result2 = 0;
cout << "Введите название команды: ";
cin >> Match.comand1;
cout << "Введите число голов, забитых командой № 1: ";
cin >> Match.count1;
cout << "Введите название команды: ";
cin >> Match.comand2;
cout << "Введите число голов, забитых командой № 2: ";
cin >> Match.count2;
ofstream fout("football.txt", ios_base::app);
fout << Match.comand1 << endl;
fout << Match.count1 << endl;
fout << Match.comand2 << endl;
fout << Match.count2 << endl;
Match = Sorting(Match);//сравнения
fout << Match.games1 << endl;
fout << Match.won1 << endl;
fout << Match.tie1 << endl;
fout << Match.lose1 << endl;
fout << Match.miss1 << endl;
fout << Match.subcount1 << endl;
fout << Match.result1 << endl;
fout << Match.games2 << endl;
fout << Match.won2 << endl;
fout << Match.tie2 << endl;
fout << Match.lose2 << endl;
fout << Match.miss2 << endl;
fout << Match.subcount2 << endl;
fout << Match.result2 << endl;
fout.close();
cout << "Данные успешно записаны в football и comand.txt\n";
cout << "Хотите ввести результаты нового матча? (y/n)и Enter) ";
cin >> choice;
choice = Check(choice);
}
if (choice == 'n')
{
cout << "Хотите узнать общий результат всех введенных матчей? (y/n) ";
cin >> choice;
choice = Check(choice);
if (choice == 'y')
{
ifstream fin("football.txt");
if (!fin.is_open())
cout << "Файл не открывается, проверьте его наличие и расположение\n"; // сообщаем об этом и подсказываем, как исправить положение
else
{
while (!fin.eof())
{
match Match;
fin >> Match.comand1;
fin >> Match.count1;
fin >> Match.comand2;
fin >> Match.count2;
fin >> Match.games1;
fin >> Match.won1;
fin >> Match.tie1;
fin >> Match.lose1;
fin >> Match.miss1;
fin >> Match.subcount1;
fin >> Match.result1;
fin >> Match.games2;
fin >> Match.won2;
fin >> Match.tie2;
fin >> Match.lose2;
fin >> Match.miss2;
fin >> Match.subcount2;
fin >> Match.result2;
matches.push_back(Match);
}
fin.close();
matches.pop_back();
}
cout << "\n";
cout << " Результаты всех матчей " << "\n";
cout << "№" << " - " << "НК" << " - " << "И" << " - " << "В" << " - " << "Н" << " - " << "П" << " - " << "ЗМ" << " - " << "ПМ" << " - " << "РМ" << " - " << "ОЧКИ" << "\n";
for (int i = 0; i < matches.size(); i++)
{
cout << i << " - " << matches[i].comand1 << " - " << matches[i].games1 << " - " << matches[i].won1 << " - " << matches[i].tie1 << " - " << matches[i].lose1 << " - " << matches[i].count1 << " - " << matches[i].miss1 << " - " << matches[i].subcount1 << " - " << matches[i].result1 << "\n";
cout << i << " - " << matches[i].comand2 << " - " << matches[i].games2 << " - " << matches[i].won2 << " - " << matches[i].tie2 << " - " << matches[i].lose2 << " - " << matches[i].count2 << " - " << matches[i].miss2 << " - " << matches[i].subcount2 << " - " << matches[i].result2 << "\n";
cout << endl;
}
}
system("pause");
}
delete[] buffer;
return 0;
} |