-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtim.cpp
96 lines (69 loc) · 1.53 KB
/
tim.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
#include "tim.h"
Tim::Tim() {
}
Tim::Tim(std::string name, int maxNumber) {
teamName = name;
maxPlayers = maxNumber;
players = new Igrac * [maxNumber];
for (int i = 0; i < maxNumber; i++)
players[i] = nullptr;
}
Tim::Tim(Tim& toCopy) {
teamName = toCopy.teamName;
maxPlayers = toCopy.maxPlayers;
currPlayers = toCopy.currPlayers;
players = new Igrac * [maxPlayers];
for (int i = 0; i < maxPlayers; i++) {
players[i] = toCopy.players[i];
}
}
void Tim::addPlayer(Igrac* newPlayer, int position) {
try {
if (currPlayers >= maxPlayers)
throw FullTeam();
players[position] = newPlayer;
++currPlayers;
}
catch (FullTeam& exception) {
exception.printMsg();
}
}
int Tim::numOfPlayers() {
return currPlayers;
}
double Tim::teamValue() {
double value = 0;
for (int i = 0; i < maxPlayers; i++) {
if (players[i]) {
value += players[i]->getPlayerValue();
}
}
value = value / currPlayers;
return value;
}
Igrac* Tim::operator[](int position) {
return players[position];
}
bool Tim::operator==(Tim& second) {
bool isEqual = false;
if (currPlayers != second.currPlayers || teamName != second.teamName)
return false;
for (int i = 0; i < currPlayers; i++) {
if (*players[i] == *second.players[i])
continue;
return false;
}
return true;
}
std::ostream& operator<<(std::ostream& it, Tim& team) {
it << team.teamName << '[';
for (int i = 0; i < team.maxPlayers; i++) {
if(team.players[i])
it << *team.players[i] << ',';
}
it << ']' << std::endl;
return it;
}
Tim::~Tim() {
delete[]players;
}