//------------------------------------------------------------------- // File :course.C // Author :Alicia Thorsen // Course :CS1129 // // Implementation of Course class. //------------------------------------------------------------------- #include "course.h" #include "student.h" #include #include #include #include using namespace std; //------------------------------------------------------------------- // Precondition: name and numericGrade contain the name and grade of a student. // Postcondition: Adds the student to the roster. //------------------------------------------------------------------- void Course::addStudent(string name, double numericGrade) { if (numOfStudents == MAX_STUDENTS) { cerr << "Exceeded max number of students for " << courseName << endl; exit(1); } roster[numOfStudents].setName(name); roster[numOfStudents].setNumericGrade(numericGrade); numOfStudents++; } //------------------------------------------------------------------- // Precondition: The roster array contains all the student information. // Postcondition: Letter grades are computed for all students. //------------------------------------------------------------------- void Course::calcLetterGrades() { for (int i = 0; i < numOfStudents; ++i) roster[i].calcLetterGrade(); } //------------------------------------------------------------------- // Precondition: The roster array contains all the student information. // Postcondition: All student data for this course is written to an output file. //------------------------------------------------------------------- void Course::outputCourseData(ofstream& fileOut) const { int tableWidth; // Left align columns. fileOut.setf(ios::left); // Write course name. fileOut << courseName << "\n" << endl; // Write table headings. fileOut << setw(NAME_COLUMN_WIDTH) << "Name" << setw(NUMERIC_GRADE_COLUMN_WIDTH) << "Numeric Grade" << "Letter Grade\n"; // Draw a line under table headings. tableWidth = NAME_COLUMN_WIDTH + (2 * NUMERIC_GRADE_COLUMN_WIDTH); for (int j = 0; j < tableWidth; ++j) fileOut << "="; fileOut << endl; // Write each student row. for (int i = 0; i < numOfStudents; ++i) { fileOut << setw(NAME_COLUMN_WIDTH) << roster[i].getName() << setw(NUMERIC_GRADE_COLUMN_WIDTH) << roster[i].getNumericGrade() << roster[i].getLetterGrade() << endl; } fileOut << endl; }