Intro CS Question #2 Free Response Review. Please fill out the following: string
ID: 3760036 • Letter: I
Question
Intro CS Question #2 Free Response Review.
Please fill out the following:
string Course::getName() {
// YOUR CODE HERE
return ""; // <--- delete this
}
// Function (getNumStudents) that returns the number of students (int) in the course
int Course::getNumStudents() {
// YOUR CODE HERE
return 0; // <--- delete this
}
void Course::addStudent(Student newStudent) {
// YOUR CODE HERE - 2 lines
}
int Course::getLowestGrade() {
int currentMin = -1;
for (int student = 0; student < numStudents; ++student) {
// YOUR CODE HERE - 3 lines
}
return currentMin;
}
int Course::getHighestGrade() {
int currentMax = -1;
for (int student = 0; student < numStudents; ++student) {
// YOUR CODE HERE - 3 lines
}
return currentMax;
}
void Course::printStudents() {
for (int student = 0; student < numStudents; ++student) {
//cout << students[student]./* YOUR CODE HERE */ << endl;
; // <--- delete this
}
}
----------------------------------------
Link to header
http://pastebin.com/XZmUT9c8
Explanation / Answer
string Course::getName() {
return name;
}
// Function (getNumStudents) that returns the number of students (int) in the course
int Course::getNumStudents() {
return numStudents;
}
void Course::addStudent(Student newStudent) {
students[numStudents] = newStudent;
numStudents++;
}
int Course::getLowestGrade() {
int currentMin = -1;
for (int student = 0; student < numStudents; ++student) {
if (currentMin > students[student].getLowestGrade()) {
currentMin = students[student].getLowestGrade();
}
}
return currentMin;
}
int Course::getHighestGrade() {
int currentMax = -1;
for (int student = 0; student < numStudents; ++student) {
if (currentMax < students[student].getHighestGrade()) {
currentMax = students[student].getHighestGrade();
}
}
return currentMax;
}
void Course::printStudents() {
for (int student = 0; student < numStudents; ++student) {
cout<<students[student].getName()<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.