Question
The code below works no issue but I want my name and professor's name to be include in the code same as course name already
The code below works no issue but I want my name and professor's name to be include in the code same as course name already in there.
main.cpp // Create GradeBook object, input grades and display grade report. // include definition of class GradeBook from GradeBook.h #include "GradeBook.h" int main() { // create GradeBook object myGradeBook and // pass course name to constructor GradeBook myGradeBook("CISP400 Object Oriented Programming with C++"); myGradeBook.displayMessage(); // display welcome message myGradeBook.inputGrades(); // read grades from user myGradeBook.displayInputs(); // display inputted information myGradeBook.displayGradeReport(); // display report based on grades myGradeBook.~GradeBook(); // call destructor myGradeBook.displayMessage(); //try to display the destroyed object information system("PAUSE"); // keeps console open return 0; // indicate successful termination } // end main
GradeBook.cpp #include #include #include "GradeBook.h" // header file using namespace std; // for asthetics // constructor initializes courseName with string supplied as argument; // initializes counter data members to 0 GradeBook::GradeBook(string name) { // constructor cout << "The Grade Book Constructor is called" << endl; // informs that constructor is opened initializeData(); // sets everything to 0 setCourseName(name); // sets course name and limits character length displayGradeReport(); // a report of all the data collected cout << " *****The end of Grade Book Constructor.***** " << endl; // informs that the constructor is over } // end GradeBook constructor void GradeBook::initializeData() // sets all variables to 0 { for (int x = 0; x <= 5; x++){ // loops through the entire array countGrades[x] = 0; // sets each array element to 0 } // end for for (int x = 0; x <= 100; x++){ // loops through the entire array letterGrades[x] = '\0'; // sets each ellement to null } courseName = 'Null'; // sets variable to null } // function to set the course name; limits name to 30 or fewer characters void GradeBook::setCourseName(string name) // takes 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 30 characters { // set courseName to first 30 characters of parameter name courseName = name.substr(0, 30); // select first 30 characters cerr << "\tName: \"" << name << "\"" << endl << "\texceeds maximum length (30). "; // tells user the name is too long cout << "\tLimiting courseName to first 30 characters. " << endl // tells user name is being shortened << "\tWelcome to the grade book for" << endl << "\t" << courseName << "! " // displays the shortened name << "The Grade Book, " << courseName << ", contains " ; } // end if...else } // end function setCourseName // function to retrieve the course name string GradeBook::getCourseName() const { return courseName; // returns 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 << "\tWelcome to the grade book for \t" << getCourseName() << "! " // calls getCourseName << endl; } // end function displayMessage // input arbitrary number of grades from user; update grade counter void GradeBook::inputGrades() { cout << "\tEnter the letter grades." << endl // asks user for grade << "\tOr enter the EOF character to end input." << endl // lets user know how to end loop << "\t(Use Ctl + D, or Ctl + Z)" << endl; // loop until user types end-of-file key sequence for (int x = 0; ((letterGrades[x] = cin.get()) != EOF) && (x <= 99); x++) // loops until ended or 100 is reached, also sets users grade to array, increments variable for next array element { getchar(); // eats to keep array from getting overloaded // determine which grade was entered switch (letterGrades[x]) // switch statement nested in while { case 'A': // grade was uppercase A case 'a': // or lowercase a countGrades[0]++; // increment aCount letterGrades[x] = toupper(letterGrades[x]); // sets letter to uppercase break; // necessary to exit switch case 'B': // grade was uppercase B case 'b': // or lowercase b countGrades[1]++; // increment bCount letterGrades[x] = toupper(letterGrades[x]);// sets letter to uppercase break; // exit switch case 'C': // grade was uppercase C case 'c': // or lowercase c countGrades[2]++; // increment cCount letterGrades[x] = toupper(letterGrades[x]);// sets letter to uppercase break; // exit switch case 'D': // grade was uppercase D case 'd': // or lowercase d countGrades[3]++; // increment dCount letterGrades[x] = toupper(letterGrades[x]);// sets letter to uppercase break; // exit switch case 'F': // grade was uppercase F case 'f': // or lowercase f countGrades[4]++; // increment fCount letterGrades[x] = toupper(letterGrades[x]);// sets letter to uppercase break; // exit switch case ' ': // ignore newlines, case '\t': // tabs, case ' ': // and spaces in input break; // exit switch default: // catch all other characters cout << "\tXXXX An incorrect letter grade entered. XXXX \t\"" // informs user that they entered an invalid grade << letterGrades[x] << "\" is not a propper letter grade. " << endl; // tells user what they entered countGrades[5]++; // counts user errors break; //optional will end switch anyways } // end switch cout << " \tEnter letter grades." << endl // tells user the loop is continuing << "\t-->\tOr Enter the EOF character to end input." << endl << "\t(Use Ctl + D, or Ctl + Z)" << endl; } // end for } // end function inputGrades // display a report based on the grades entered by user void GradeBook::displayGradeReport() const { // output summary of results int grades = 0; // counter for # of grades entered int data = 0; // grades + errors for (int x = 0; x <= 4; x++) // loop to count grades { grades += countGrades[x]; // counts each grade } data = (grades + countGrades[5]); // total number of user entries cout << " The total number of data entered is " << data; // tells user how many characters they input cout << " The total number of students receive grades is " << grades; // tells user how many valid grades they entered cout << " Number of students who received each letter grade:" // title for following list of grades << " A: \t" << countGrades[0] // display number of A grades << " B: \t" << countGrades[1] // display number of B grades << " C: \t" << countGrades[2] // display number of C grades << " D: \t" << countGrades[3] // display number of D grades << " F: \t" << countGrades[4] // display number of F grades << " Error:\t" << countGrades[5] // display number of errors << endl << endl; // spacing cout << "The class average is: " << fixed << setprecision (1) << calculateGrade() << endl; // calls calculateGrade function and limits it to one decimal } // end function displayGradeReport void GradeBook::displayInputs() // displays a list of every character entered { cout << " The data entered is listed as the following: "; for (int x = 0; letterGrades[x] != EOF && (x <= 99); x++) // loops until the end of the array is reached { cout << "[" << x << "] -> " << letterGrades[x] << "\t"; // displays array element if ((x + 1) % 4 == 0) { // checks to see if 4 elements have been printed in row cout << endl; // ends row at 4 } } cout << endl; // spacer } // end function displayInputs // calculates and returns the GPA double GradeBook::calculateGrade() const { double data = 0; // double to include desimal for (int x = 0; x <= 4; x++) // counts valid grades { data += countGrades[x]; // adds up all valid grades } // end for double x = 0; if (data == 0) // in case user entered no valid grades, protects against dividing by 0 { data = 1; // will divide by 1 } // end if x = ((countGrades[0] * 4) + (countGrades[1] * 3) + (countGrades[2] * 2) + (countGrades[3] * 1)) / data; // gives grades their value and calculates GPA return x; // returns GPA } // end function GradeBook // deconstructor GradeBook::~GradeBook() { cout << " Destructor is called " << endl; // tells user deconstructor was called } // end deconstructor GradeBook.h #include using namespace std; // for asthetics // GradeBook class definition class GradeBook { public: explicit GradeBook(string); // initialize course name void setCourseName(string); // set the course name 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 void displayInputs(); // displays all the input data 4 per row void initializeData(); // sets all variable and arrays to 0 double calculateGrade() const; // calculates gpa ~GradeBook(); // destructor private: char letterGrades [100]; // stores all the input information int countGrades [6]; // stores the number of each letter grade and number of the errors input string courseName; // course name for this GradeBook }; // 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