Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#ifndef Student_h #define Student_h #include <string> using namespace std; const

ID: 3759808 • Letter: #

Question

#ifndef Student_h

#define Student_h

#include <string>

using namespace std;

const int MAX_NUM_GRADES = 20;

class Student {

private:

/**

   * Instance variables that represent a student

   * Marked as private so that they are not able to be changed outside of this

   * class

   */

  

// The full name of this student

string name;

  

// An array of grades recorded for this student

int grades[MAX_NUM_GRADES] = { };

  

// The number of valid grades for this student, used to know the upper bound

// of the grades[] array

int numGrades = 0;

  

public:

/**

   * Requires: name of the student

   * Modifies: name

   * Effects : Student constructor for when only a student name is given.

   * Note that numGrades is 0 and grades[] is all 0's, given by

   * their declarations.

   */

Student(string name);

  

/**

   * Requires: nothing

   * Modifies: name

   * Effects : Default Student constructor. name is set to be an empty string.

   * Note that numGrades is 0 and grades[] is all 0's, given by

   * their declarations.

   */

Student();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the name of this Student instance.

   */

string getName();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the number of grades contained by this Student instance.

   */

int getNumGrades();

  

/**

   * Requires: An integer (score) representing the grade to add, 0 to 100 inclusive

   * Modifies: grades[] and numGrades

   * Effects : Adds the passed score to the list of grades for this Student

   * instance and increments the number of grades that this Student

   * instance contains.

   */

void addGrade(int score);

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the lowest grade in the list of grades for this

   * Student instance. Returns -1 if there are no grades.

   */

int getLowestGrade();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the highest grade in the list of grades for this

   * Student instance. Returns -1 if there are no grades.

   */

int getHighestGrade();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Calculates and returns the average grade given all of this

   * Student instance's grades. Returns 0 if there are no grades.

   */

double getAverageGrade();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns a string, suitable for printing, that contains this

   * Student instance's name, average grade, and the number of

   * grades stored.

   */

string printableSummary();

};

#endif /* Student_h */

#ifndef Course_h

#define Course_h

#include <iostream>

#include "Student.h"

using namespace std;

const int MAX_NUM_STUDENTS = 100;

class Course {

private:

/**

   * Instance variables that represent a course

   * Marked as private so that they are not able to be changed outside of this

   * class

   */

  

// The name of this course (e.g., EECS 183)

string name;

  

// An array that holds all of the students that have been added to this course

Student students[MAX_NUM_STUDENTS];

  

// The number of students in this course, used to know the upper bound of

// the students[] array

int numStudents = 0;

  

public:

/**

   * Requires: name of the course

   * Modifies: nothing

   * Effects : Constructor for when only a course name is given.

   * Note that numStudents is 0 and students[] is uninitialized,

   * given by their declarations.

   */

Course(string courseName);

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the name of this Course instance.

   */

// Function (getName) that returns the name (string) of this Course

string getName();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the number of students contained by this Course instance.

   */

// Function (getNumStudents) that returns the number of students (int) in

// this course

int getNumStudents();

  

/**

   * Requires: A Student instance

   * Modifies: students[] and numStudents

   * Effects : Adds the passed student to the list of students for this Course

   * instance and increments the number of students that this Course

   * instance contains.

   */

void addStudent(Student newStudent);

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the lowest grade given all grades by all students in this

   * Course instance. Returns -1 if there are no students.

   */

int getLowestGrade();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Returns the highest grade given all grades by all students in this

   * Course instance. Returns -1 if there are no students.

   */

int getHighestGrade();

  

/**

   * Requires: nothing

   * Modifies: nothing

   * Effects : Calculates and returns the average grade given all of this

   * Course instance's student's average grade. Returns 0 if there

   * are no grades.

   */

double getAverageGrade();

  

/**

   * Requires: nothing

   * Modifies: cout

   * Effects : Prints out the student summary for every student contained in

   * this Course instance.

   */

void printStudents();

};

#endif /* Course_h */

#include "Course.h"

Course::Course(string courseName) {

name = courseName;

}

// Function (getName) that returns the name (string) of this Course

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;

}

double Course::getAverageGrade() {

double total = 0.0;

  

for (int student = 0; student < numStudents; ++student) {

total += students[student].getAverageGrade();

}

  

// Handle special case of 0 students

if (numStudents == 0) {

return 0;

}

  

return total / numStudents;

}

void Course::printStudents() {

for (int student = 0; student < numStudents; ++student) {

//cout << students[student]./* YOUR CODE HERE */ << endl;

; // <--- delete this

}

}

Explanation / Answer

#ifndef Student_h
#define Student_h

#include <string>

using namespace std;

const int MAX_NUM_GRADES = 20;

class Student {
private:
/**
* Instance variables that represent a student
* Marked as private so that they are not able to be changed outside of this
* class
*/
  
// The full name of this student
string name;
  
// An array of grades recorded for this student
int grades[MAX_NUM_GRADES] = { };
  
// The number of valid grades for this student, used to know the upper bound
// of the grades[] array
int numGrades = 0;
  
public:
/**
* Requires: name of the student
* Modifies: name
* Effects : Student constructor for when only a student name is given.
* Note that numGrades is 0 and grades[] is all 0's, given by
* their declarations.
*/
Student(string name);
  
/**
* Requires: nothing
* Modifies: name
* Effects : Default Student constructor. name is set to be an empty string.
* Note that numGrades is 0 and grades[] is all 0's, given by
* their declarations.
*/
Student();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the name of this Student instance.
*/
string getName();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the number of grades contained by this Student instance.
*/
int getNumGrades();
  
/**
* Requires: An integer (score) representing the grade to add, 0 to 100 inclusive
* Modifies: grades[] and numGrades
* Effects : Adds the passed score to the list of grades for this Student
* instance and increments the number of grades that this Student
* instance contains.
*/
void addGrade(int score);
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the lowest grade in the list of grades for this
* Student instance. Returns -1 if there are no grades.
*/
int getLowestGrade();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the highest grade in the list of grades for this
* Student instance. Returns -1 if there are no grades.
*/
int getHighestGrade();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Calculates and returns the average grade given all of this
* Student instance's grades. Returns 0 if there are no grades.
*/
double getAverageGrade();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns a string, suitable for printing, that contains this
* Student instance's name, average grade, and the number of
* grades stored.
*/
string printableSummary();
};


#endif /* Student_h */


#ifndef Course_h
#define Course_h

#include <iostream>
#include "Student.h"


using namespace std;

const int MAX_NUM_STUDENTS = 100;

class Course {
private:
/**
* Instance variables that represent a course
* Marked as private so that they are not able to be changed outside of this
* class
*/
  
// The name of this course (e.g., EECS 183)
string name;
  
// An array that holds all of the students that have been added to this course
Student students[MAX_NUM_STUDENTS];
  
// The number of students in this course, used to know the upper bound of
// the students[] array
int numStudents = 0;
  
public:
/**
* Requires: name of the course
* Modifies: nothing
* Effects : Constructor for when only a course name is given.
* Note that numStudents is 0 and students[] is uninitialized,
* given by their declarations.
*/
Course(string courseName);
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the name of this Course instance.
*/
// Function (getName) that returns the name (string) of this Course
string getName();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the number of students contained by this Course instance.
*/
// Function (getNumStudents) that returns the number of students (int) in
// this course
int getNumStudents();
  
/**
* Requires: A Student instance
* Modifies: students[] and numStudents
* Effects : Adds the passed student to the list of students for this Course
* instance and increments the number of students that this Course
* instance contains.
*/
void addStudent(Student newStudent);
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the lowest grade given all grades by all students in this
* Course instance. Returns -1 if there are no students.
*/
int getLowestGrade();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Returns the highest grade given all grades by all students in this
* Course instance. Returns -1 if there are no students.
*/
int getHighestGrade();
  
/**
* Requires: nothing
* Modifies: nothing
* Effects : Calculates and returns the average grade given all of this
* Course instance's student's average grade. Returns 0 if there
* are no grades.
*/
double getAverageGrade();
  
/**
* Requires: nothing
* Modifies: cout
* Effects : Prints out the student summary for every student contained in
* this Course instance.
*/
void printStudents();
};

#endif /* Course_h */

#include "Course.h"

Course::Course(string courseName) {
name = courseName;
}

// Function (getName) that returns the name (string) of this Course
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;
}

double Course::getAverageGrade() {
double total = 0.0;
  
for (int student = 0; student < numStudents; ++student) {
total += students[student].getAverageGrade();
}
  
// Handle special case of 0 students
if (numStudents == 0) {
return 0;
}
  
return total / numStudents;
}

void Course::printStudents() {
for (int student = 0; student < numStudents; ++student) {
//cout << students[student]./* YOUR CODE HERE */ << endl;
; // <--- delete this
}
}