-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1_10685093.cc.cpp
413 lines (375 loc) · 14.7 KB
/
p1_10685093.cc.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#include <iostream>
#include <cstring>
#include <stdlib.h>
using namespace std;
class Student{
public:
string FirstName;
string LastName;
string StudentNumber;
double Grade;
};
class Course{
public:
string Name;
string creditHours;
string CourseNumber;
Student registeredStudents[100];
void AddCourses(string CourseName, string CreditHours, string CourseNumber){
this->Name = CourseName;
this->creditHours = CreditHours;
this->CourseNumber = CourseNumber;
}
void EditCourse(string CourseName, string CreditHours, string CourseNumber){
this->Name = CourseName;
this->creditHours = CreditHours;
this->CourseNumber = CourseNumber;
}
void AddStudentToCourse(Student obj){
registeredStudents[indexOfStudent]=obj;
cout << "Enter Course Grade: ";
cin >> registeredStudents[indexOfStudent].Grade;
indexOfStudent++;
cout << "Student Added To Course" << endl;
}
void PrintStudentGrade(string studentNumber){
int index =0; bool isFound=false;
for (int i=0; i<=indexOfStudent; i++){
if (studentNumber == registeredStudents[i].StudentNumber){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound == true){
cout << this->Name << ": " << registeredStudents[index].Grade <<endl;
}
}
private:
int indexOfStudent=0;
};
class Staff{
public:
string FirstName;
string LastName;
string CourseName;
string StaffNumber;
};
class ArrayInfo{
public:
int studentArrayIndex=0;
int courseArrayIndex=0;
int staffArrayIndex=0;
};
int main()
{
Course courses[100]; Student students[100]; Staff staffs[100];
ArrayInfo IndexInfo;
string userInput;
string selectOperator;
do{
//system("cls");
cout << "Enter course to select Course, student to select Student, staff \nto select Staff or exit to Exit System, print to Print Records: ";
cin >> selectOperator;
if (selectOperator == "course"){
cout << "Select An Operation:" <<endl;
cout << "Enter add to Add Course | edit to Edit Course | delete to Delete Course | assign to Student to a course"<<endl;
cin >> userInput;
if (userInput == "add"){
cout << "\nYou have chosen to add to a new Course" << endl;
cout << "Enter Course Name: ";
cin >> courses[IndexInfo.courseArrayIndex].Name;
cout << "Enter Course Number: ";
cin >> courses[IndexInfo.courseArrayIndex].CourseNumber;
cout << "Enter Credit Hours of Course: ";
cin >> courses[IndexInfo.courseArrayIndex].creditHours;
cout << "Course Added!" << endl;
IndexInfo.courseArrayIndex++;
}
else if (userInput == "edit"){
string courseName; int index; bool isFound=false;
cout << "\nYou have chosen to edit to a Course" << endl;
cout << "Enter Course Name: ";
cin >> courseName;
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
if (courseName == courses[i].Name){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound = true){
cout << "Course Found" << endl;
cout << "Enter New Course Name: ";
cin >> courses[index].Name;
cout << "Enter New Course Number: ";
cin >> courses[index].CourseNumber;
cout << "Enter New Credit Hours of Course: ";
cin >> courses[index].creditHours;
cout << "Course has been successfully edited!" << endl;
}
else{
cout << "Course Not Found" <<endl;
}
}
else if (userInput == "delete"){
string courseName; int index=0; bool isFound=false;
cout << "Enter Course Name: ";
cin >> courseName;
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
if (courseName == courses[i].Name){
index = i;
isFound = true;
break;
}
else{
isFound = false;
}
}
if (isFound == true){
for (int i=index; i<=IndexInfo.courseArrayIndex; i++){
if (!((i++) > IndexInfo.courseArrayIndex)){
courses[i] = courses[i++];
}
}
IndexInfo.courseArrayIndex--;
}
else{
}
}
else if (userInput == "list"){
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
cout << courses[i].Name << endl;
}
}
else if (userInput == "assign"){
string studentNumber; bool isFound=false; int index=0;
cout << "Enter Student's Student Number: ";
cin >> studentNumber;
for (int i=0; i<=IndexInfo.studentArrayIndex; i++){
if (students[i].StudentNumber == studentNumber){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound == true){
string courseName;
cout << "Student Found" << endl;
cout << "Enter Course Name To Be Assigned To: ";
cin >> courseName;
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
if (courses[i].Name == courseName){
cout << "Course Found" << endl;
courses[i].AddStudentToCourse(students[index]);
isFound=true;
}
else{
isFound=false;
}
}
}
else{
}
}
}
else if (selectOperator == "student"){
cout << "Select An Operation:" <<endl;
cout << "Enter add to Add Student|edit to Edit Student|delete to Delete Student"<<endl;
cin >> userInput;
if (userInput == "add"){
cout << "\nYou have chosen to add to a new Student" << endl;
cout << "Enter Student First Name: ";
cin >> students[IndexInfo.studentArrayIndex].FirstName;
cout << "Enter Student Last Name: ";
cin >> students[IndexInfo.studentArrayIndex].LastName;
cout << "Enter Student's Student Number: ";
cin >> students[IndexInfo.studentArrayIndex].StudentNumber;
cout << "Student Added!" << endl;
IndexInfo.studentArrayIndex++;
}
else if (userInput == "edit"){
string studentNumber; int index; bool isFound=false;
cout << "\nYou have chosen to edit to a Student" << endl;
cout << "Enter Student's Student Number: ";
cin >> studentNumber;
for (int i=0; i<=IndexInfo.studentArrayIndex; i++){
if (studentNumber == students[i].StudentNumber){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound = true){
cout << "Student Found" << endl;
cout << "Enter Student First Name: ";
cin >> students[index].FirstName;
cout << "Enter Student Last Name: ";
cin >> students[index].LastName;
cout << "Enter Student's Student Number: ";
cin >> students[index].StudentNumber;
cout << "Student's Details has been successfully edited!" << endl;
}
else{
cout << "Course Not Found" <<endl;
}
}
else if (userInput == "delete"){
string studentNumber; int index=0; bool isFound=false;
cout << "Enter Student's Student Number: ";
cin >> studentNumber;
for (int i=0; i<=IndexInfo.studentArrayIndex; i++){
if (studentNumber == students[i].StudentNumber){
index = i;
isFound = true;
break;
}
else{
isFound = false;
}
}
if (isFound == true){
for (int i=index; i<=IndexInfo.studentArrayIndex; i++){
if (!((i++) > IndexInfo.studentArrayIndex)){
students[i] = students[i++];
}
}
IndexInfo.studentArrayIndex--;
}
else{
}
}
else if (userInput == "list"){
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
cout << courses[i].Name << endl;
}
}
}
else if (selectOperator == "staff"){
cout << "Select An Operation:" <<endl;
cout << "Enter add to Add Staff | edit to Edit Staff | delete to Delete Staff"<<endl;
cin >> userInput;
if (userInput == "add"){
cout << "\nYou have chosen to add to a new Staff" << endl;
cout << "Enter Staff's First Name: ";
cin >> staffs[IndexInfo.staffArrayIndex].FirstName;
cout << "Enter Staff's Last Name: ";
cin >> staffs[IndexInfo.staffArrayIndex].LastName;
cout << "Enter Staff's Staff Number: ";
cin >> staffs[IndexInfo.staffArrayIndex].StaffNumber;
cout << "Enter Staff's Course Name: ";
cin >> staffs[IndexInfo.staffArrayIndex].CourseName;
cout << "Staff Added to List!" << endl;
IndexInfo.staffArrayIndex++;
}
else if (userInput == "edit"){
string staffNumber; int index; bool isFound=false;
cout << "\nYou have chosen to edit to a Staff" << endl;
cout << "Enter Staff's Staff Number: ";
cin >> staffNumber;
for (int i=0; i<=IndexInfo.staffArrayIndex; i++){
if (staffNumber == staffs[i].StaffNumber){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound = true){
cout << "Staff Found" << endl;
cout << "Enter Staff's First Name (New): ";
cin >> staffs[index].FirstName;
cout << "Enter Staff's Last Name: ";
cin >> staffs[index].LastName;
cout << "Enter Staff's Staff Number: ";
cin >> staffs[index].StaffNumber;
cout << "Staff's Details has been successfully edited!" << endl;
}
else{
cout << "Staff Not Found" <<endl;
}
}
else if (userInput == "delete"){
string staffNumber; int index=0; bool isFound=false;
cout << "Enter Staff's Staff Number: ";
cin >> staffNumber;
for (int i=0; i<=IndexInfo.staffArrayIndex; i++){
if (staffNumber == staffs[i].StaffNumber){
index = i;
isFound = true;
break;
}
else{
isFound = false;
}
}
if (isFound == true){
for (int i=index; i<=IndexInfo.staffArrayIndex; i++){
if (!((i++) > IndexInfo.staffArrayIndex)){
staffs[i] = staffs[i++];
}
}
IndexInfo.staffArrayIndex--;
}
else{
}
}
else if (userInput == "list"){
for (int i=0; i<=IndexInfo.staffArrayIndex; i++){
cout << staffs[i].FirstName << " " <<staffs[i].LastName << endl;
}
}
}
else if (selectOperator == "print"){
string studentNumber; int index; bool isFound=false;
cout << "\nYou have chosen to print Student's Results" << endl;
cout << "Enter Student's Student Number: ";
cin >> studentNumber;
for (int i=0; i<=IndexInfo.studentArrayIndex; i++){
if (studentNumber == students[i].StudentNumber){
index=i;
isFound=true;
break;
}
else{
isFound=false;
}
}
if (isFound == true){
cout << "Student Found" << endl;
cout << "Student's Results" << endl;
cout << "Full Name: " << students[index].FirstName << " "
<< students[index].LastName << endl;
cout << "Course List" << endl;
for (int i=0; i<=IndexInfo.courseArrayIndex; i++){
courses[i].PrintStudentGrade(studentNumber);
}
}
else{
cout << "Student Not Found" << endl;
}
}
else if (selectOperator == "exit"){
cout << "System Exited"<< endl;
return 0;
}
else{
cout << "Invalid Operator"<< endl;
}
}while (true);
return 0;
}