-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDivision.cpp
186 lines (183 loc) · 4.4 KB
/
Division.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
#include <vector>
#include <iostream>
#include "Player.h"
#include <string>
#include "role.h"
#include "Division.h"
using namespace std;
Division::Division(string name)
{
m_name = name;
}
double Division::getAverageSR()
{
double total = 0;
for (int i = 0; i < m_division.size(); i++)
{
total += m_division[i].m_sr;
}
return total / m_division.size();
}
int Division::getSR(int index)
{
return m_division[index].m_sr;
}
std::string Division::getName(int index)
{
return m_division[index].m_name;
}
std::string Division::getBattletag(int index)
{
return m_division[index].m_battletag;
}
Role Division::getRole(int index)
{
return m_division[index].m_role;
}
int Division::search(int sr)
{
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_sr == sr)
return i;
}
cout << "None found with that SR.\n";
return -1;
}
vector<int> Division::searchAll(int sr) //searches for all players with that sr
{
vector<int> solutions;
int count = 0;
solutions.resize(count);
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_sr == sr)
{
count++;
solutions.resize(count);
solutions[count - 1] = i;
}
}
if (solutions.size() == 0)
{
cout << "None found with that SR.\n";
solutions.resize(1);
solutions[0] = -1;
}
return solutions;
}
bool isIncluded(vector<int> list, int check)
{
for (int i = 0; i < list.size(); ++i)
{
if (check == list[i])
return true;
}
return false;
}
int Division::search(int sr, vector<int> exeptions) //searches for a player with "sr" sr. Ignores any players with their index in the "exeptions"
{
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_sr == sr && !isIncluded(exeptions, i))
return i;
}
cout << "None found with that SR that was not in the exeptions.\n";
return -1;
}
int Division::search(string name) //searches for a player with that name
{
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_name == name || m_division[i].m_battletag == name)
return i;
}
cout << "None found with that SR.\n";
return -1;
}
int Division::search(string name, vector<int> exeptions) //same as above, with exeptions
{
for (int i = 0; i < m_division.size(); ++i)
{
if ((m_division[i].m_name == name || m_division[i].m_battletag == name) && !isIncluded(exeptions, i))
return i;
}
cout << "None found with that name or battletag that was not in the exeptions.\n";
return -1;
}
int Division::search(int lower, int upper) //searches for a player that is >= lower and <= upper
{
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_sr <= upper && m_division[i].m_sr >= lower)
return i;
}
cout << "None found within that range.\n";
return -1;
}
int Division::search(int lower, int upper, Role role)
{
for (int i = 0; i < m_division.size(); ++i)
{
if ((m_division[i].m_sr <= upper && m_division[i].m_sr >= lower) && m_division[i].m_role == role)
{
return i;
}
}
cout << "None found within that range and with that role\n";
return -1;
}
vector<int> Division::searchAll(int lower, int upper, Role role) //same as above, but all players.
{
vector<int> solutions;
int count = 0;
solutions.resize(count);
for (int i = 0; i < m_division.size(); ++i)
{
if (m_division[i].m_sr <= upper && m_division[i].m_sr >= lower && m_division[i].m_role == role)
{
count++;
solutions.resize(count);
solutions[count - 1] = i;
}
}
if (solutions.size() == 0)
{
cout << "None found within that range and with that role.\n";
solutions.resize(1);
solutions[0] = -1;
}
return solutions;
}
int Division::countRole(Role role)
{
int count = 0;
for (int i = 0; i < m_division.size(); i++)
{
if (m_division[i].m_role == role)
count++;
}
switch (role)
{
case ROLE_DPS:
cout << "There are " << count << " DPS players on " << m_name << "\n";
break;
case ROLE_TANK:
cout << "There are " << count << " Tank players on " << m_name << "\n";
break;
case ROLE_SUPPORT:
cout << "There are " << count << " Support players on " << m_name << "\n";
break;
case ROLE_ANY:
cout << "There are " << count << " Any players on " << m_name << "\n";
break;
}
return count;
}
void Division::tallyRoles()
{
countRole(ROLE_DPS);
countRole(ROLE_TANK);
countRole(ROLE_SUPPORT);
countRole(ROLE_ANY);
}