-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFootballTeam.cpp
188 lines (177 loc) · 3.6 KB
/
FootballTeam.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
#include <iostream>
#include <cstring>
using namespace std;
class FudbalskaEkipa
{
protected:
char trener[100];
int golovi[10];
public:
FudbalskaEkipa(char trener1[100], int golovi1[10])
{
strcpy(trener, trener1);
for (int i = 0; i < 10; i++)
{
golovi[i] = golovi1[i];
}
}
virtual int uspeh() = 0;
bool operator>(FudbalskaEkipa &f)
{
if (uspeh() > f.uspeh())
{
return true;
}
else
return false;
}
char *getTrener()
{
return trener;
}
virtual char *getIme() = 0;
FudbalskaEkipa &operator+=(int g)
{
for (int i = 0; i < 10; i++)
{
golovi[i - 1] = golovi[i];
}
golovi[9] = g;
return *this;
}
};
class Klub : public FudbalskaEkipa
{
private:
char ime[100];
int brojTituli;
public:
Klub(char trener1[100], int golovi1[10], char ime1[100], int brojTituli1)
: FudbalskaEkipa(trener1, golovi1)
{
strcpy(ime, ime1);
brojTituli = brojTituli1;
}
char *getIme()
{
return ime;
}
int uspeh()
{
int a = 0;
int b = 0;
for (int i = 0; i < 10; i++)
{
a += golovi[i];
}
a *= 3;
b = brojTituli * 1000;
return a + b;
}
};
class Reprezentacija : public FudbalskaEkipa
{
private:
char imeDrzava[100];
int nastapi;
public:
Reprezentacija(char trener1[100], int golovi1[10], char im[100], int n)
: FudbalskaEkipa(trener1, golovi1)
{
strcpy(imeDrzava, im);
nastapi = n;
}
int uspeh()
{
int a = 0, b = 0;
for (int i = 0; i < 10; i++)
{
a += golovi[i];
}
a *= 3;
b = nastapi * 50;
return a + b;
}
char *getIme()
{
return imeDrzava;
}
};
ostream &operator<<(ostream &out, FudbalskaEkipa &f)
{
FudbalskaEkipa *tmp = &f;
out << tmp->getIme() << endl;
out << tmp->getTrener() << endl;
out << tmp->uspeh() << endl;
return out;
}
void najdobarTrener(FudbalskaEkipa **ekipa, int n)
{
int max = 0;
for (int i = 0; i < n; i++)
{
if (ekipa[i]->uspeh() > ekipa[max]->uspeh())
{
max = i;
}
}
cout << *ekipa[max];
}
int main()
{
int n;
cin >> n;
FudbalskaEkipa **ekipi = new FudbalskaEkipa *[n];
char coach[100];
int goals[10];
char x[100];
int tg;
for (int i = 0; i < n; ++i)
{
int type;
cin >> type;
cin.getline(coach, 100);
cin.getline(coach, 100);
for (int j = 0; j < 10; ++j)
{
cin >> goals[j];
}
cin.getline(x, 100);
cin.getline(x, 100);
cin >> tg;
if (type == 0)
{
ekipi[i] = new Klub(coach, goals, x, tg);
}
else if (type == 1)
{
ekipi[i] = new Reprezentacija(coach, goals, x, tg);
}
}
cout << "===== SITE EKIPI =====" << endl;
for (int i = 0; i < n; ++i)
{
cout << *ekipi[i];
}
cout << "===== DODADI GOLOVI =====" << endl;
for (int i = 0; i < n; ++i)
{
int p;
cin >> p;
cout << "dodavam golovi: " << p << endl;
*ekipi[i] += p;
}
cout << "===== SITE EKIPI =====" << endl;
for (int i = 0; i < n; ++i)
{
cout << *ekipi[i];
}
cout << "===== NAJDOBAR TRENER =====" << endl;
najdobarTrener(ekipi, n);
for (int i = 0; i < n; ++i)
{
delete ekipi[i];
}
delete[] ekipi;
return 0;
}