Question
Can only modify Gradebook.h and Gradebook.cpp Cannot modify CISP400V10A3.cpp file In C++ Create a GradeBook class that calculates a grade-point average for a set of
Can only modify Gradebook.h and Gradebook.cpp
Cannot modify CISP400V10A3.cpp file
In C++
Create a GradeBook class that calculates a grade-point average for a set of grades and displays information. You can input A, a, B, b, C, c, D, d, F and f for grades. But the inputted data could also be any characters, upper case, lower case or special character. The system should detect an improper grade input and allow reentering information. The grade of A is worth 4 points, B is worth 3 points, etc. You can use GradeBook program (attached) as a starting point.
The GradeBook class has the following methods and attributes.
The GradeBook class has 3 private data members, courseName, letterGrades and countGrades.
The courseName has a string data type. It stores course name information.
The letterGrades is a 100 elements character array. It stores all the inputs information which include the letter grades and non-letter grade information. For example, if you put a, $, a, C, 1, ! for the first 6 inputs the letterGrades first six elements should store A, $, A, C, 1, !.
The countGrades is a 6 elements integer array. It stores the number of each letter grade and number of the error(s) input. For example, if you input 5 As, 6 Bs, 1 C, 2 Ds, 2 Es and 3 Fs, the countGrades array elements from 0 to 5 should contain 5, 6, 1, 2, 3 and 2.
It also has several public member functions, GradeBook, setCourseName, getCourseName, initializeData, displayMessage, inputGrades, displayGradeReport, displayInputs, calculateGrade and ~GradeBook.
The GradeBook function is a constructor. It takes a string and will initialize its data members data. The constructor also displays information which includes The Grade Book Constructor is called", *****The end of Grade Book Constructor.***** and the information in between these two statements.
The setCourseName function takes a string and does not return anything. This function sets information for the string private data, courseName. It takes only the first 30 characters of the input string. If the inputted string shorter than 30 it will take everything. If it is longer than 30 it will keep the first 30 characters and truncate the rest of the information.
The getCourseName function returns the private data, courseName, information. It does not accept any data.
The initializeData function does not take and return anything. It initializes the private data members.
The displayMessage function does not take and return anything. It displays "Welcome to the grade book for " information.
The inputGrades function does not take and return anything. It generates loops to get any number(but it need to be less than 100) of proper data input. If the inputted data is not any one of the following A, a, B, b, C, c, E, d, F, and f, the program will show ****Incorrect letter grade entered.**** message. The loop will be ended by inputting Ctl + D, or Ctl + Z ( it depends on your computer system).
The displayGradeReport function does not accept and return any data. It displays The total number of students receive grades is ", "Number of students who received each letter grade and The class average is information. The class average is displayed in one digit double value.
The displayInputs function does not accept and return any data. It displays The data entered is listed at the following: " as a heading and all the grades (information) entered in a 4 in a row tabulate format.
The calculateGrade function does not accept any data but return a double value. This function calculates the GPA (Grade Point Average) and return the data.
i.The ~GradeBook function is the destructor of the class. When it called it will clean up the memory and displays Destructor is called message.
Driver Files
_______________________________________________
// V10A3.cpp
// Creating a GradeBook object and calling its member functions.
#include "GradeBook.h" // include definition of class GradeBook
int main()
{
// create GradeBook object
GradeBook myGradeBook( "CISP400 Object Oriented programming" );
myGradeBook.displayMessage(); // display welcome message
myGradeBook.inputGrades(); // read grades from user
myGradeBook.displayGradeReport(); // display report based on grades
system("PAUSE");
} // end main
____________________________________________________________
// 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() <= 25 ) // if name has 25 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, 25 ); // select first 25 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
// 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.h // GradeBook class definition that counts letter grades. // Member functions are defined in GradeBook.cpp #include // program uses C++ standard string class
// GradeBook class definition class GradeBook { public: explicit GradeBook( std::string ); // initialize course name void setCourseName( std::string ); // set the course name std::string getCourseName() const; // retrieve the course name void displayMessage() const; // display a welcome message void inputGrades(); // input arbitrary number of grades from user void displayGradeReport() const; // display report based on user input private: std::string courseName; // course name for this GradeBook unsigned int aCount; // count of A grades unsigned int bCount; // count of B grades unsigned int cCount; // count of C grades unsigned int dCount; // count of D grades unsigned int fCount; // count of F grades }; // end class GradeBook
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started