Question: Redo HW13/HW16 (or do it for the first time : ), but this time youll overload 3 operators ( == , >> , and <

Redo HW13/HW16 (or do it for the first time : ), but this time youll overload 3 operators ( ==, >>, and <<). The idea is very similar to the examples we talked about in class using the class CCircNum with the files called OpOver1.cpp and Streams2.cpp. When youre overloading the extractor and insertion operators youll want to use the member functions you already created (i.e. DispGrade and GetInfo). However, youll want to now provide arguments to those two functions.

DispGrade should now have an ostream argument which defaults to cout. In addition, the entire function should be a constant. We talked about this idea in class and you can reference Streams2.cpp for help on that.

GetInfo should now have an istream argument that defaults to cin.

operator>> should have two arguments and return an istream by reference. Refer your notes on specifics for this.

operator<< should also have two arguments and return an ostream by reference.

For both the extraction and insertion operators, which one should have a constant parameter? Once you figure that out, implement it as so.

operator== should have an object passed by reference as a parameter and return a boolean. How should you check each private member, specifically the cstring? I suggest looking into the cstring library for help on that.

Note: If you get a warning in your type constructor saying deprecated conversion from string constant to char* dont worry about it as the class progress we will figure out a way to understand and get rid of this warning.

The program has 3 files total. A header file called cgradeOverload.h, where your class should be declared. An implementation file called cgradeOverload.cpp, where your functions implementations are stored. Lastly, youll need a file to store main called main.cpp. You can use your existing code and change it where you need to. You can save your files in your HW17 directory.

To help you get started, I went ahead and created a HW17 subdirectory for you and put starter kit in there called CGradeOverloadStarterKit.tar.gz. This is a compressed archive file, much like a zip file, it contains files that need to be extracted. To extract the files, use this command:

 tar xvzf CGradeOverloadStarterKit.tar.gz 

This will extract the files contained within the archive into the present working directory. You should then find a completed main.cpp and a partially completed cgradeOverload.h files and an executable file. Youll need to fill in the ??? in cgradeOverload.h and create the implementation of the functions in a file called cgradeOverload.cpp. You can copy and paste your previous cgrade.cpp file and change the two functions (DispGrade and GetInfo) and add the implementation of the overloaded functions. To run the example executable is ./GradeCalcOverload

NOTE: You only need to extract the files once! If you extract the cpp file, write some code, and then extract again at a later point in time, the original cpp file in the archive will be extracted and overwrite any code that you've already written!

A sample run is below:

$ ./GradeCalcOverload Default Constructor! Type Constructor! Copy Constructor! The grades of S1 (default constructor): NULL: 0.0% F Enter student's full name, Quiz 1 grade (out of 10.0), Quiz 2 grade (out of 10.0), midterm grade (out of 100.0), and final exam grade (out of 100.0). (HIT ENTER AFTER EACH ONE!!!) Elon Musk 6 7 73 88 S1 != S2 S2 == S3 The grades of the students are: Elon Musk: 78.5% C Edgar Allen Poe: 0.0% F Edgar Allen Poe: 0.0% F

This is main.cpp

#include #include #include "cgradeOverload.h" using namespace std;

// ==== main ================================================================== // // ============================================================================

int main() { CGrade S1; // first student CGrade S2("Edgar Allen Poe"); // second student CGrade S3(S2); // copy of the second student

// Display the default constructor info cout << " The grades of S1 (default constructor): "; cout << S1;

// prompt the user for name/grades cout << " Enter student's full name, Quiz 1 grade (out of " << QUIZ1 << "), " << "Quiz 2 grade (out of " << QUIZ2 << "), midterm grade (out of " << MIDTERM << "), " << "and final exam grade (out of " << FINAL << "). (HIT ENTER AFTER EACH ONE!!!) ";

cin >> S1;

// call the function to calculate percent/grade S1.CalcGrade();

// check if S1 == S2 and S2 == S3 if (S1 == S2) { cout << " S1 == S2 "; } else { cout << " S1 != S2 "; }

if (S2 == S3) { cout << " S2 == S3 "; } else { cout << " S2 != S3 "; }

// display their grades cout << " The grades of the students are: "; cout << S1; cout << S2; cout << S3;

return 0; } // end of "main"

This is cgradeOverload.h

#ifndef CGRADE_HEADER #define CGRADE_HEADER #include using namespace std;

// constant grade values const double QUIZ1 = 10; const double QUIZ2 = 10; const double MIDTERM = 100; const double FINAL = 100;

class CGrade { public: // constructors CGrade(); // default constructor CGrade(char sName[], double quiz1 = 0, double quiz2 = 0, double midterm = 0, double finalExam = 0, double percent = 0, char grade = 'F'); // type CGrade(CGrade &object); // copy constructor

// member functions void GetInfo(???); void CalcGrade(void); void CalcPercent(void); void DispGrade(???) ???;

// overloaded operators (==) ???

private: // data members char m_name[256]; double m_quiz1; double m_quiz2; double m_midterm; double m_finalExam; double m_percent; char m_grade; };

// overloaded streams ??? ???

#endif // CGRADE_HEADER

This is HW13

You are to write a program for a class with the following grading policies:

There are two quizzes, each graded on the basis of 10 points.

There is one midterm exam and one final exam, each graded on the basis of 100 points.

The final exam counts for 50 percent of the grade, the midterm counts for 25 percent, and the two quizzes together count for a total of 25 percent.

Any grade of 90 or more is an A, any grade 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F.

The program will read in the name and scores of only 2 students and output the students name, percentage, and grade for the class. Define and use a structure for the student record. A sample run is below:

$ ./a.out Info for S1: Enter student's full name: Edgar Allen Poe Enter Quiz 1 grade (out of 10): 9 Enter Quiz 2 grade (out of 10): 10 Enter midterm grade (out of 100): 98 Enter final exam grade (out of 100): 97 Info for S2: Enter student's full name: Elon Musk Enter Quiz 1 grade (out of 10): 6 Enter Quiz 2 grade (out of 10): 7 Enter midterm grade (out of 100): 73 Enter final exam grade (out of 100): 88 The grades of the students are: Edgar Allen Poe: 96.8% A Elon Musk: 78.5% C

Here are the guidelines for how it will be programmed. First and foremost, the structure will be called Grade and it will have 7 variables inside of it: quiz1, quiz2, midterm, finalExam, percent, name, and grade. Quiz1, quiz2, midterm, and final exam will be a double that contains the score the student received. Percent will have the weighted percent for the class. Grade is a char that will hold the overall class grade. And name is a char array that will hold the students first, middle (if any), and last name.

In main, youll create and allocate space for 2 students using the structure. Youll then pass as reference, one at a time, the student info structure to a function called GetInfo which will collect the information needed to fill the majority of the structure (quiz1, quiz2, midterm, finalExam, and name). Then main will call the CalcGrade function and pass by reference, one at a time, the student info structure to calculate the overall grade for each student. Finally, main will call the DispGrade function, passing each structure by value (also one at a time), to display the final grade for each student.

GetInfo will initialize the structure for each student with the grade they received for each quiz, midterm, and final exam as well as their full name. This will have a void return type and a parameter of pass by reference.

CalcGrade will call the function CalcPercent to calculate the percentage of the student. Then CalcGradewill use the update information in the structure to assign the appropriate grade. This will have a void return type and a parameter of pass by reference.

CalcPercent will calculate the weighted percentage for the student. This will have a void return type and a parameter of pass by reference.

DispGrade will display the name, percentage, and grade for each student. Note that the percentage will be displayed with only one decimal value (tenths place). This will have a void return type and a parameter of pass by value.

On Canvas, Ill post up a flowchart for you to better understand the flow of the program. You can save your code in a file named studentGrades.cpp in your HW13 directory.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!