Question: C++ Instruction is located here: https://www.chegg.com/homework-help/questions-and-answers/c-multiple-links-complete-project-direction-https-wwwcheggcom-homework-help-questions-answ-q69094689 // GradeBook.cpp // Member-function definitions for class GradeBook that // uses a switch statement to count A, B, C,
C++
Instruction is located here: https://www.chegg.com/homework-help/questions-and-answers/c-multiple-links-complete-project-direction-https-wwwcheggcom-homework-help-questions-answ-q69094689
// GradeBook.cpp // Member-function definitions for class GradeBook that // uses a switch statement to count A, B, C, D and F grades. #include #include "GradeBook.h" // include definition of class GradeBook using namespace std;
// constructor initializes courseName with string supplied as argument; // initializes counter data members to 0 GradeBook::GradeBook(string name) : aCount(0), // initialize count of A grades to 0 bCount(0), // initialize count of B grades to 0 cCount(0), // initialize count of C grades to 0 dCount(0), // initialize count of D grades to 0 fCount(0) // initialize count of F grades to 0 { setCourseName(name); } // end GradeBook constructor
// function to set the course name; limits name to 25 or fewer characters void GradeBook::setCourseName(string name) { if (name.size() <= 30) // if name has 30 or fewer characters courseName = name; // store the course name in the object else // if name is longer than 25 characters { // set courseName to first 25 characters of parameter name courseName = name.substr(0, 30); // select first 30 characters cerr << "Name \"" << name << "\" exceeds maximum length (25). " << "Limiting courseName to first 25 characters. " << endl; } // end if...else } // end function setCourseName
// function to retrieve the course name string GradeBook::getCourseName() const { return courseName; } // end function getCourseName
void GradeBook::initializeData() { for (int x = 0; x <= 5; x++) //loop to set element to 0 { countGrades[x] = 0; }
for (int x = 0; x <= 100; x++) // loop to set lenght/null { letterGrades[x] = '\0'; }
courseName = 'Null'; // set variable to null }
// display a welcome message to the GradeBook user void GradeBook::displayMessage() const { // this statement calls getCourseName to get the // name of the course this GradeBook represents cout << "Welcome to the grade book for " << getCourseName() << "! " << endl; } // end function displayMessage
// input arbitrary number of grades from user; update grade counter void GradeBook::inputGrades() { int grade; // grade entered by user
cout << "Enter the letter grades." << endl << "Enter the EOF character to end input." << endl;
// loop until user types end-of-file key sequence while ((grade = cin.get()) != EOF) { // determine which grade was entered switch (grade) // switch statement nested in while { case 'A': // grade was uppercase A case 'a': // or lowercase a ++aCount; // increment aCount break; // necessary to exit switch
case 'B': // grade was uppercase B case 'b': // or lowercase b ++bCount; // increment bCount break; // exit switch
case 'C': // grade was uppercase C case 'c': // or lowercase c ++cCount; // increment cCount break; // exit switch
case 'D': // grade was uppercase D case 'd': // or lowercase d ++dCount; // increment dCount break; // exit switch
case 'F': // grade was uppercase F case 'f': // or lowercase f ++fCount; // increment fCount break; // exit switch
case ' ': // ignore newlines, case '\t': // tabs, case ' ': // and spaces in input break; // exit switch
default: // catch all other characters cout << "Incorrect letter grade entered." << " Enter a new grade." << endl; break; // optional; will exit switch anyway } // end switch } // end while } // end function inputGrades
// display a report based on the grades entered by user void GradeBook::displayGradeReport() const { // output summary of results cout << " Number of students who received each letter grade:" << " A: " << aCount // display number of A grades << " B: " << bCount // display number of B grades << " C: " << cCount // display number of C grades << " D: " << dCount // display number of D grades << " F: " << fCount // display number of F grades << endl; } // end function displayGradeReport
GradeBook::~GradeBook() // Call/Display destructor { cout << endl << "Destructor is called" << endl; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
