-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroster.cpp
265 lines (214 loc) · 8.33 KB
/
roster.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include <iostream>
#include <string>
#include <sstream>
#include <array>
#include <iomanip>
#include "roster.h"
#include "student.h"
#include "degree.h"
#include "securityStudent.h"
#include "softwareStudent.h"
#include "networkStudent.h"
using namespace std;
Roster::Roster() {}
/* --------------------------ADD FUNCTION ---------------------------------------*/
void Roster::add(string studID, string fiName, string laName, string emAddr, int a, int day0, int day1, int day2, Degree degree) {
int nmDaysIn[] = { day0, day1, day2 };
//incrementIndex++ PREVENTS OVERWRITING NEW
if (degree == Degree::NETWORKING) {
classRosterArray[incrementIndex++] = new NetworkStudent(studID, fiName, laName, emAddr, a, nmDaysIn, degree);
}
if (degree == Degree::SECURITY) {
classRosterArray[incrementIndex++] = new SecurityStudent(studID, fiName, laName, emAddr, a, nmDaysIn, degree);
}
if (degree == Degree::SOFTWARE) {
classRosterArray[incrementIndex++] = new SoftwareStudent(studID, fiName, laName, emAddr, a, nmDaysIn, degree);
}
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* ------------------------------PRINTING ALL STUDENTS-------------------- */
void Roster::printAll() {
cout << " STUDENT ROSTER:" << endl;
cout << endl;
for (int i = 0; i < 5; i++) {
(*classRosterArray[i]).print();
}
//cout << setfill('-') << setw(100) << "" << endl;
cout << endl;
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* -----------------------DISPLAYING INVALID EMAILS--------------------------------------- */
void Roster::printInvalidEmails() {
cout << " INVALID STUDENT EMAILS:" << endl;
cout << endl;
bool hasSpace = false;
bool hasAt = false;
bool hasDot = false;
string studentEmail;
for (int i = 0; i < 5; i++) {
studentEmail = (*classRosterArray[i]).GetEmailAddress();
//checking for spaces on email string
if (studentEmail.find(' ') != string::npos) {
hasSpace = true;
}
else {
hasSpace = false;
}
//checking for at symbol on email string
if (studentEmail.find('@') != string::npos) {
hasAt = true;
}
else {
hasAt = false;
}
//checking for dot on email string
if (studentEmail.find('.') != string::npos) {
hasDot = true;
}
else {
hasDot = false;
}
//invalid emails have spaces and are missing a dot or at symbol
if (hasSpace == true || hasAt == false || hasDot == false) {
cout << " -" << (*classRosterArray[i]).GetEmailAddress() << endl;
}
}
cout << endl;
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* -----------------------------PRINTING AVERAGE OF DAYS---------------------------------------- */
//gets days by index then sum and division
void Roster::printAverageDaysInCourse(string studentID) {
cout << " COURSE COMPLETION RATE AVERAGE: " << endl;
cout << endl;
for (int i = 0; i < 5; i++) {
if ((*classRosterArray[i]).GetStudentID() == studentID) {
int average = 0;
average = ((*classRosterArray[i]).GetNumDays()[0] + (*classRosterArray[i]).GetNumDays()[1] + (*classRosterArray[i]).GetNumDays()[2] ) / 3;
//cout << " The average days it took the student with studentID: " << studentID << " to finish 3 courses: " << average << '\n';
cout << " StudentID: " << studentID << "\t" << " Average: " << average << endl;
}
}
cout << endl;
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* ------------------PRINTING STUDENTS OF THE DEGREE SPECIFIED IN THE PARAMETER-------------- */
void Roster::printByDegreeProgram(string degree) {
Degree studentsByDegree;
if (degree == "NETWORKING") {
studentsByDegree = Degree::NETWORKING;
cout << " STUDENTS IN THE NETWORKING PROGRAM: " << endl;
}
if (degree == "SOFTWARE") {
studentsByDegree = Degree::SOFTWARE;
cout << " STUDENTS IN THE SOFTWARE PROGRAM: " << endl;
}
if (degree == "SECURITY") {
studentsByDegree = Degree::SECURITY;
cout << " STUDENTS IN THE SECURITY PROGRAM: " << endl;
}
cout << endl;
for (int i = 0; i < 5; i++) {
if (studentsByDegree == (*classRosterArray[i]).getDegree()) {
(*classRosterArray[i]).print();
}
}
cout << endl;
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* --------------------REMOVING STUDENT USING STUDENT ID----------------------------------------- */
void Roster::remove(string studentID) {
bool studentRemoved = false;
for (int i = 0; i < 5; i++) {
if (classRosterArray[i] != NULL) {
if (studentID == classRosterArray[i]->GetStudentID()) {
classRosterArray[i] = nullptr;
studentRemoved = true;
}
}
}
if (!studentRemoved) {
cout << " ***The student with the ID: " << studentID << " was not found." << '\n';
}
}
/* -----------------------------FUNCTION END---------------------------------------- */
/* -----------------------------MAIN---------------------------------------- */
int main()
{
const string studentData[] =
{ "A1,John,Smith,John1989@gm ail.com,20,30,35,40,SECURITY",
"A2,Suzan,Erickson,Erickson_1990@gmailcom,19,50,30,40,NETWORK",
"A3,Jack,Napoli,The_lawyer99yahoo.com,19,20,40,33,SOFTWARE",
"A4,Erin,Black,[email protected],22,50,58,40,SECURITY",
"A5,Manuel,Fuentes,[email protected],30,32,35,37,SOFTWARE"
};
//Creating Roster Instance
Roster classRoster;
// Creating Degree Instance
Degree myDegree;
/* --------------------------CODE FOR SEPARATING STUDENT DATA ITEMS ----------------------------- */
for (int i = 0; i < 5; i++) {
//read student id
int commaFind = studentData[i].find(",");
string sID = studentData[i].substr(0, commaFind);
//read student first name
int secSubs = commaFind + 1; //starting from first character after the last comma
commaFind = studentData[i].find(",", secSubs);
string sFN = studentData[i].substr(secSubs, commaFind - secSubs);
//read student last name
int thirdSubs = commaFind + 1;
commaFind = studentData[i].find(",", thirdSubs);
string sLN = studentData[i].substr(thirdSubs, commaFind - thirdSubs);
//read student email
int fourthSubs = commaFind + 1;
commaFind = studentData[i].find(",", fourthSubs);
string sEM = studentData[i].substr(fourthSubs, commaFind - fourthSubs);
//read student age
int fifthSubs = commaFind + 1;
commaFind = studentData[i].find(",", fifthSubs);
int sAG = stoi(studentData[i].substr(fifthSubs, commaFind - fifthSubs));
//read student day 1 of array
int sixthSubs = commaFind + 1;
commaFind = studentData[i].find(",", sixthSubs);
int sDay1 = stoi(studentData[i].substr(sixthSubs, commaFind - sixthSubs));
//read student day 2 of array
int sevenSubs = commaFind + 1;
commaFind = studentData[i].find(",", sevenSubs);
int sDay2 = stoi(studentData[i].substr(sevenSubs, commaFind - sevenSubs));
//read student day 3 of array
int eightSubs = commaFind + 1;
commaFind = studentData[i].find(",", eightSubs);
int sDay3 = stoi(studentData[i].substr(eightSubs, commaFind - eightSubs));
//read student degree
int ninthSubs = commaFind + 1;
commaFind = studentData[i].find(",", ninthSubs);
string mydegree = studentData[i].substr(ninthSubs, commaFind - ninthSubs);
//assigning the appropiate degree to each string
if (mydegree == "NETWORK") {
myDegree = Degree::NETWORKING;
}
if (mydegree == "SOFTWARE") {
myDegree = Degree::SOFTWARE;
}
if (mydegree == "SECURITY") {
myDegree = Degree::SECURITY;
}
classRoster.add(sID, sFN, sLN, sEM, sAG, sDay1, sDay2, sDay3, myDegree);
}
/* -------------------END OF SEPARATING STUDENT DATA ITEMS ----------------------------- */
/*------------------ PRINTING PERSONAL INFO --------------------------------------------*/
cout << endl;
cout << " Scripting and Programming - Applications C867" << endl;
cout << " Manuel Fuentes" << endl;
cout << " Student ID #000990664" << endl;
cout << endl;
// printing all results
classRoster.printAll();
classRoster.printInvalidEmails();
classRoster.printAverageDaysInCourse("A1");
classRoster.printByDegreeProgram("SOFTWARE");
classRoster.remove("A3");
classRoster.remove("A3"); //CHECK IF STUDENT WAS REMOVED
}
//Deconstructor
Roster::~Roster() {}