-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchool.cpp
executable file
·134 lines (108 loc) · 2.2 KB
/
School.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
#include "School.h"
School::School() : students(), teams()
{
}
StatusType School::AddStudent(int StudentID, int Grade, int Power)
{
if ((StudentID < 1) ||
(Grade < 0) ||
(Power < 1)) {
return INVALID_INPUT;
}
Student * s = new Student(StudentID, Grade, Power);
if (s == NULL) {
return ALLOCATION_ERROR;
}
if (!this->students.AddStudent(s)) {
delete s;
return FAILURE;
}
return SUCCESS;
}
StatusType School::AddTeam(int TeamID)
{
if (TeamID < 1) {
return INVALID_INPUT;
}
Team * t = new Team(TeamID);
if (t == NULL) {
return ALLOCATION_ERROR;
}
if (!this->teams.insert(TeamID, t)) {
delete t;
return FAILURE;
}
return SUCCESS;
}
StatusType School::MoveStudentToTeam(int StudentID, int TeamID)
{
if ((StudentID < 1) ||
(TeamID < 1)) {
return INVALID_INPUT;
}
Student * s = NULL;
Team * t = NULL;
try {
s = this->students.GetStudent(StudentID);
t = this->teams.searchInTree(TeamID);
}
catch (DataNotFound) {
return FAILURE;
}
s->SwitchTeam(t);
return SUCCESS;
}
StatusType School::GetMostPowerful(int TeamID, int *StudentID)
{
if ((TeamID == 0) ||
(StudentID == NULL)) {
return INVALID_INPUT;
}
if (TeamID < 0) {
*StudentID = this->students.GetStrongestStudentID();
} else {
Team * t = NULL;
try {
t = this->teams.searchInTree(TeamID);
}
catch (DataNotFound) {
return FAILURE;
}
*StudentID = t->GetStrongestStudentID();
}
return SUCCESS;
}
StatusType School::RemoveStudent(int StudentID)
{
if (StudentID < 1) {
return INVALID_INPUT;
}
Student * s = this->students.GetStudent(StudentID);
if (s == NULL) {
return FAILURE;
}
s->GetTeam()->RemoveStudent(s);
this->students.RemoveStudent(s);
delete s;
return SUCCESS;
}
//StatusType School::GetAllStudentsByPower(int TeamID, int **Students, int *numOfStudents);
StatusType School::IncreaseLevel(int Grade, int PowerIncrease)
{
if ((Grade < 0) ||
(PowerIncrease < 1)) {
return INVALID_INPUT;
}
int length = 0;
Student * s = this->students.GetAllStudents(&length);
if (length == -1) {
return ALLOCATION_ERROR;
}
for (int i = 0; i < length; ++i) {
if (s->GetGrade() == Grade) {
s->IncreasePower(PowerIncrease);
}
}
delete[] s;
return SUCCESS;
}