-
Notifications
You must be signed in to change notification settings - Fork 0
/
Team.cpp
99 lines (87 loc) · 2.22 KB
/
Team.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
#include "Team.h"
Team& Team::matchInFinals(Team& other)
{
int counterWinsFirst = 0;
int counterWinsSecond = 0;
int pointsOfTeams[2][3]; //2 teams play up to 3 rounds
//first array stores teams, second array stores rounds
std::cout << getName() << " vs. " << other.getName();
for (int i = 0; i < 2; i++)
{
std::cout << i + 1 << "-st game: "; std::cin >> pointsOfTeams[0][0]; std::cout << " - "; std::cin >> pointsOfTeams[1][0];
pointsTeam += pointsOfTeams[0][i];
other.setPoints(other.getPoints() + pointsOfTeams[1][i]);
if (pointsTeam > other.getPoints()) counterWinsFirst++;
else counterWinsSecond++;
}
if (counterWinsFirst == counterWinsSecond)
{
std::cout << "Final game: "; std::cin >> pointsOfTeams[0][2]; std::cout << " - "; std::cin >> pointsOfTeams[1][2];
pointsTeam += pointsOfTeams[0][2];
other.setPoints(other.getPoints() + pointsOfTeams[1][2]);
if (pointsTeam > other.getPoints()) counterWinsFirst++;
else counterWinsSecond++;
}
if (counterWinsFirst > counterWinsSecond) return *this;
else if (counterWinsFirst < counterWinsSecond) return other;
}
void Team::copyTeam(const Team& team)
{
nameTeam = new char[strlen(team.nameTeam) + 1];
assert(nameTeam);
strcpy(nameTeam, team.nameTeam);
pointsTeam = team.pointsTeam;
differencePoints = team.differencePoints;
}
Team::Team(const char* name, int points)
{
nameTeam = new char[strlen(name) + 1];
assert(nameTeam);
strcpy(nameTeam, name);
pointsTeam = points;
differencePoints = 0;
}
Team::Team(const Team& team)
{
copyTeam(team);
}
Team& Team::operator=(const Team& team)
{
if (this != &team)
{
delete[] nameTeam;
copyTeam(team);
}
return *this;
}
Team::~Team()
{
delete[] nameTeam;
}
const char* Team::getName() const
{
return nameTeam;
}
int Team::getPoints() const
{
return pointsTeam;
}
int Team::getDifferencePoints() const
{
return differencePoints;
}
void Team::setDifferencePoints(int points)
{
differencePoints = points;
}
void Team::setName(const char* name)
{
delete[] nameTeam;
nameTeam = new char[strlen(name) + 1];
assert(nameTeam);
strcpy(nameTeam, name);
}
void Team::setPoints(int points)
{
pointsTeam = points;
}