-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstructor.cpp
More file actions
204 lines (190 loc) · 6.36 KB
/
Instructor.cpp
File metadata and controls
204 lines (190 loc) · 6.36 KB
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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
#include "Instructor.h"
#include "Student.h"
using namespace std;
/* A method to allow the instructor to login and access the class features.
Given a username and password, checks if that is an instructor and their
password, then returns True if the instructor succeeded or False if not.
*/
bool Instructor::login(string u, string p) {
bool log;
if (u == userName && p == password) {
log = true;
} else {
log = false;
}
return log;
} // login
/* Retreives the instructor's full name so that the message "You are now
logged in as ____" can be displayed.
*/
string Instructor::getInstructorName() {
return fullName;
} // getinstructorname
string Instructor::getUserName() {
return userName;
}
/* Given the username of a student, allows the instructor to see the grades
of the student provided.
*/
Student Instructor::getStudent(Student students[], string username, int numStuds) {
Student stu;
int i;
string user = username;
for (i = 0; i < numStuds; i++) {
if (students[i].getUserName() == user) {
return students[i];
stu = students[i];
return stu;
}
}
cout << "Student username is not valid" << endl;
return stu;
} // getstudent
/* Retrieves the student with the lowest grade of a given type. */
void Instructor::getMinStudent(Student students[], int gradeType, int numStuds) {
Student stu;
int i;
int min = 100;
if (gradeType == 1) {
for (i = 0; i < numStuds; i++) {
if (students[i].getProjectGrade() < min) {
min = students[i].getProjectGrade();
stu = students[i];
}
}
cout << min << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 2) {
for (i = 0; i < numStuds; i++) {
if (students[i].getQuizGrade() < min) {
min = students[i].getQuizGrade();
stu = students[i];
}
}
cout << min << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 3) {
for (i = 0; i < numStuds; i++) {
if (students[i].getMidtermGrade() < min) {
min = students[i].getMidtermGrade();
stu = students[i];
}
}
cout << min << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 4) {
for (i = 0; i < numStuds; i++) {
if (students[i].getFinalGrade() < min) {
min = students[i].getFinalGrade();
stu = students[i];
}
}
cout << min << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 5) {
for (i = 0; i < numStuds; i++) {
if (students[i].getOverallGrade() < min) {
min = students[i].getOverallGrade();
stu = students[i];
}
}
cout << min << "%\t(" << stu.getStudentName() << ")" << endl;
} else {
cout << "Invalid grade type, please enter 1 - 5." << endl;
}
} // getminstudent
/* Retrieves the student with the highest grade of a given type. */
void Instructor::getMaxStudent(Student students[], int gradeType, int numStuds) {
Student stu;
int i;
int max = 0;
if (gradeType == 1) {
for (i = 0; i < numStuds; i++) {
if (students[i].getProjectGrade() > max) {
max = students[i].getProjectGrade();
stu = students[i];
}
}
cout << max << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 2) {
for (i = 0; i < numStuds; i++) {
if (students[i].getQuizGrade() > max) {
max = students[i].getQuizGrade();
stu = students[i];
}
}
cout << max << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 3) {
for (i = 0; i < numStuds; i++) {
if (students[i].getMidtermGrade() > max) {
max = students[i].getMidtermGrade();
stu = students[i];
}
}
cout << max << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 4) {
for (i = 0; i < numStuds; i++) {
if (students[i].getFinalGrade() > max) {
max = students[i].getFinalGrade();
stu = students[i];
}
}
cout << max << "%\t(" << stu.getStudentName() << ")" << endl;
} else if (gradeType == 5) {
for (i = 0; i < numStuds; i++) {
if (students[i].getOverallGrade() > max) {
max = students[i].getOverallGrade();
stu = students[i];
}
}
cout << max << "%\t(" << stu.getStudentName() << ")" << endl;
} else {
cout << "Invalid grade type, please enter 1 - 5." << endl;
}
} // getmaxstudent
/* Retrieves the average grade of all students for a given grade type */
void Instructor::getAvg(Student students[], int gradeType, int numStuds) {
Student stu;
int i;
double avg = 0;
double sum = 0;
if (gradeType == 1) {
for (i = 0; i < numStuds; i++) {
sum = sum + students[i].getProjectGrade();
}
avg = sum / numStuds;
} else if (gradeType == 2) {
for (i = 0; i < numStuds; i++) {
sum = sum + students[i].getQuizGrade();
}
avg = sum / numStuds;
} else if (gradeType == 3) {
for (i = 0; i < numStuds; i++) {
sum = sum + students[i].getMidtermGrade();
}
avg = sum / numStuds;
} else if (gradeType == 4) {
for (i = 0; i < numStuds; i++) {
sum = sum + students[i].getFinalGrade();
}
avg = sum / numStuds;
} else if (gradeType == 5) {
for (i = 0; i < numStuds; i++) {
sum = sum + students[i].getOverallGrade();
}
avg = sum / numStuds;
} else {
cout << "Invalid grade type, please enter 1 - 5." << endl;
}
cout << avg << "%" << endl;
} // getavg
/* Sets the name of the instructor that has logged in. */
void Instructor::setInstructorName(string fname, string lname) {
fullName = fname + " " + lname;
}
void Instructor::setUserName(string uname) {
userName = uname;
}
void Instructor::setPassword(string pass) {
password = pass;
}