-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistrationList.cpp
165 lines (146 loc) · 4.29 KB
/
RegistrationList.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
#include <stdlib.h>
#include <iostream>
#include <vector>
#include "RegistrationList.h"
#include "StudentList.h"
#include "CourseList.h"
RegistrationList::RegistrationList() {
crn = "";
bNumber = "";
capacity = 1;
currentQuantity = 0;
allRegistrations = new Registration[capacity];
}
RegistrationList::RegistrationList(string newBNumber, string newCRN) {
bNumber = newBNumber;
crn = newCRN;
capacity = 1;
currentQuantity = 0;
allRegistrations = new Registration[capacity];
}
RegistrationList::~RegistrationList() {
delete[] allRegistrations;
}
bool RegistrationList::check(Registration orgReg, Registration newReg) {
for(int i = 0; i < currentQuantity; i++) {
if(orgReg.getBNumber() == newReg.getBNumber() && orgReg.getCRN() == newReg.getCRN()) {
return true;
}
}
return false;
}
bool RegistrationList::checkRegExists(Registration newReg) {
if(currentQuantity == 0) {
return true;
}
for(int i = 0; i < currentQuantity; i++) {
if(check(allRegistrations[i], newReg)) {
return false;
}
}
return true;
}
vector<string> RegistrationList::returnBnum(string newCRN) {
vector<string> bNumbers;
for(int i = 0; i < currentQuantity; i++) {
if(allRegistrations[i].getCRN() == newCRN) {
bNumbers.push_back(allRegistrations[i].getBNumber());
}
}
return bNumbers;
}
vector<string> RegistrationList::returnCrn(string newBNumber) {
vector<string> crns;
for(int i = 0; i < currentQuantity; i++) {
if(allRegistrations[i].getBNumber() == newBNumber) {
crns.push_back(allRegistrations[i].getCRN());
}
}
return crns;
}
void RegistrationList::addReg(Registration addReg) {
if(currentQuantity == capacity){
resizeArray();
}
allRegistrations[currentQuantity] = addReg;
printAdd();
currentQuantity += 1;
}
void RegistrationList::dropReg(Registration dropReg) {
if(currentQuantity == 1) {
currentQuantity -= 1;
printDrop(dropReg);
}
else {
int position;
for(int i = (currentQuantity-1);i >= 0; i--) {
if(check(allRegistrations[i], dropReg)) {
position = i;
}
}
if(position == currentQuantity - 1) {
currentQuantity -= 1;
}
else {
while(position < currentQuantity) {
allRegistrations[position] = allRegistrations[position+1];
position++;
}
currentQuantity -= 1;
}
printDrop(dropReg);
}
}
void RegistrationList::cancelReg(string cancelReg) {
Registration* temp = new Registration[capacity];
for(int i = 0; i <= currentQuantity; i++) {
temp[i] = allRegistrations[i];
}
int size = currentQuantity;
if(currentQuantity == 1) {
currentQuantity -= 1;
}
else {
for(int i = (size-1); i >= 0; i--) {
if(temp[i].getCRN() == cancelReg) {
if(i == size - 1) {
currentQuantity -= 1;
}
else {
int j = i;
while(j < size-1) {
allRegistrations[j] = allRegistrations[j+1];
j++;
}
currentQuantity -= 1;
}
}
}
}
delete[] temp;
printCancel(cancelReg);
}
void RegistrationList::resizeArray(){
capacity = capacity * 2;
Registration* newReg = new Registration[capacity];
for(int i = 0; i < currentQuantity; i++){
newReg[i] = allRegistrations[i];
}
delete[] allRegistrations;
allRegistrations = newReg;
}
void RegistrationList::printCancel(string cancelReg) {
cout << "Success: cancelled course " << cancelReg << endl;
}
void RegistrationList::printDrop(Registration dropReg) {
cout << "Success: removed student " << dropReg.getBNumber() << " from course " << dropReg.getCRN() << endl;
}
void RegistrationList::printAdd() {
cout << "Success: added student " << allRegistrations[currentQuantity].getBNumber() << " into course " << allRegistrations[currentQuantity].getCRN() << endl;
}
string RegistrationList::getBNumber(){
return bNumber;
}
string RegistrationList::getCRN() {
return crn;
}