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
| #include <iostream>
#include <string>
#include <fstream>
#include <list>
#include <Windows.h>
using namespace std;
class Footballer
{
string Name;
string Surname;
int Number;
string Position;//амплуа
public:
Footballer(string _Name="", string _Surname="", string _Position="", int _Number=0)
{
Name=_Name;
Surname=_Surname;
Number=_Number;
Position=_Position;
}
string getName() const
{
return Name;
}
void setName(string _Name)
{
Name=_Name;
}
string getSurname() const
{
return Surname;
}
void setSurname(string _Surname)
{
Surname=_Surname;
}
string getPosition() const
{
return Position;
}
void setPosition(string _Position)
{
Position=_Position;
}
friend ostream & operator<<(ostream & os, const Footballer & Obj);
friend ofstream &operator<<(ofstream &os, const Footballer &Obj);
};
ostream & operator<<(ostream & os, const Footballer & Obj)
{
os<<"Имя: "<<Obj.Name<<" ";
os<<"Фамилия: "<<Obj.Surname<<" ";
os<<"Амплуа: "<<Obj.Position<<" ";
os<<"Номер: "<<Obj.Number;
return os;
}
ofstream &operator<<(ofstream &os, const Footballer & Obj)
{
os<<Obj.Name.c_str()<<endl;
os<<Obj.Surname.c_str()<<endl;
os<<Obj.Position.c_str()<<endl;
os<<Obj.Number<<endl;
return os;
}
class FC
{
string Name_FC;
list <Footballer> fc;
public:
FC(string _Name_FC="")
{
Name_FC=_Name_FC;
}
void AddFootballer(const Footballer & footballer)
{
fc.push_back(footballer);
}
friend ostream & operator<<(ostream & os, const FC & Obj);
friend ofstream & operator<<(ofstream &os, const FC &Obj);
void Write(string file)
{
ofstream os(file);
if(os.is_open())
{
os<<*this;
os.close();
}
else
{
cout<<"Ошибка открытия файла "<<file<<endl;
}
}
void Read(string file)
{
ifstream is(file);
if(is.is_open())
{
getline(is, Name_FC);
string footballerName;
string footballerSurname;
string footballerPosition;
while(getline(is, footballerName))
{
string footballerNumber;
fflush(stdin);
getline(is, footballerNumber);
fflush(stdin);
int number = atoi(footballerNumber.c_str());
Footballer footballer(footballerName, footballerSurname, footballerPosition, number);
fc.push_back(footballer);
}
is.close();
}
else
{
cout<<"Ошибка открытия файла "<<file<<endl;
}
}
};
ostream & operator<<(ostream & os, const FC & Obj)
{
os<<"Команда: "<<Obj.Name_FC<<endl;
for(list<Footballer>::const_iterator it = Obj.fc.begin(); it!= Obj.fc.end(); it++)
{
os<<*it<<endl;
}
return os;
}
ofstream & operator<<(ofstream &os, const FC &Obj)
{
os<<Obj.Name_FC.c_str()<<endl;
for(list<Footballer>::const_iterator it=Obj.fc.begin(); it!=Obj.fc.end(); it++)
{
os<<*it;
}
return os;
}
class Judge
{
string Name;
string Type;
public:
Judge(string _Name="", string _Type="")
{
Name=_Name;
Type=_Type;
}
string getName() const
{
return Name;
}
void setName(string _Name)
{
Name=_Name;
}
string getType() const
{
return Type;
}
void setType(string _Type)
{
Type=_Type;
}
friend ostream & operator<<(ostream & os, const Judge & Obj);
friend ofstream & operator<<(ofstream &os, const Judge &Obj);
};
ostream & operator<<(ostream & os, const Judge & Obj)
{
os<<"Имя судьи: "<<Obj.Name;
os<<"Вид: "<<Obj.Type;
return os;
}
ofstream & operator<<(ofstream & os, const Judge & Obj)
{
os<<Obj.Name.c_str()<<endl;
os<<Obj.Type.c_str()<<endl;
return os;
}
class Game
{
string Team1;
string Team2;
int res1;
int res2;
string Town;
string date;
FC fc;
list<FC> f1;
list <Judge> jd;
public:
Game(string _Team1="", string _Team2="", string _date="", string _Town="", int _res1=0, int _res2=0)
{
Team1 = _Team1;
Team2 = _Team2;
date = _date;
Town = _Town;
res1 = _res1;
res2 = _res2;
}
void AddJudge(const Judge & judge)
{
jd.push_back(judge);
}
friend ostream &operator<<(ostream &os, const Game &Obj);
friend ofstream &operator<<(ofstream &os, const Game &Obj);
void Write(string file)
{
ofstream os(file);
if(os.is_open())
{
os<<*this;
os.close();
}
else
{
cout<<"Ошибка открытия файла "<<file<<endl;
}
}
void Read(string file)
{
ifstream is(file);
if(is.is_open())
{
getline(is, Team1);
getline(is, Team2);
getline(is, date);
getline(is, Town);
string judgeName;
string judgeType;
while(getline(is, judgeName))
{
string judgeType;
fflush(stdin);
getline(is, judgeType);
fflush(stdin);
Judge judge(judgeName, judgeType);
jd.push_back(judge);
}
is.close();
}
else
{
cout<<"Ошибка открытия файла "<<file<<endl;
}
}
};
ofstream &operator<<(ofstream &os, const Game &Obj)
{
os<<Obj.Team1.c_str()<<"-"<<Obj.Team2.c_str()<<endl;
os<<Obj.date.c_str()<<endl;
os<<Obj.Town.c_str()<<endl;
os<<Obj.res1<<":"<<Obj.res2<<endl;
return os;
for(list<FC>::const_iterator it = Obj.f1.begin(); it!= Obj.f1.end(); it++)
{
os<<*it<<endl;
}
return os;
for(list<Judge>::const_iterator it = Obj.jd.begin(); it!= Obj.jd.end(); it++)
{
os<<*it<<endl;
}
return os;
}
ostream &operator<<(ostream &os, const Game &Obj)
{
os<<"Встреча: "<<Obj.Team1<<"-"<<Obj.Team2<<endl;
os<<"Дата проведения матча: "<<Obj.date<<endl;
os<<"Место проведения: "<<Obj.Town<<endl;
os<<"Результат игры: "<<Obj.res1<<":"<<Obj.res2<<endl;
return os;
for(list<FC>::const_iterator it = Obj.f1.begin(); it!= Obj.f1.end(); it++)
{
os<<*it<<endl;
}
return os;
for(list<Judge>::const_iterator it = Obj.jd.begin(); it!= Obj.jd.end(); it++)
{
os<<*it<<endl;
}
return os;
}
void main()
{
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
Footballer footballer[3]={Footballer("Евгений", "Хачериди", "защитник", 34), Footballer("Артём","Милевский","нападающий",10), Footballer("Александр", "Шовковский", "голкипер", 1)};
Judge judge[3]={Judge ("Иван Смирнов", "1-ой боковой арбитр"), Judge("Николай Самсонов", "главный арбитр"), Judge("Арсен Микоян", "2-ой боковой арбитр")};
FC fc("Динамо К");
for(int i=0; i<3; i++)
{
fc.AddFootballer(footballer[i]);
}
cout<<fc;
Game game("Днепр Д", "Карпаты Л", "27.10.2012", "Днепропетровск", 1, 0);
for(int i=0; i<3; i++)
{
game.AddJudge(judge[i]);
}
game.Write("data123.txt");
fc.Write("data.txt");
fc.Read("data.txt");
game.Read("data123.txt");
} |