Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Redo HW13: Student Grades (or do it for the first time : ), but this time change the structure to a class named CGrade .

Redo HW13: Student Grades (or do it for the first time : ), but this time change the structure to a class named CGrade. The class should have member variables for all input data (quiz1, quiz2, midterm, finalExam, percent, name, and grade). Make all member variables private. Include member functions, the same as the ones in HW13(GetInfo, CalcGrade, CalcPercent, and DispGrade). The member functions should all be public. Also, include the 3 special constructor functions. Create a default, type, and copy constructors. The default constructor will assign zeros (0s) to all grades and percent, give the name NULL to the student, and set the grade to an F. This should be displayed first in main to show that everything is zeroed out. The type constructor should take as parameters all of your private member variables with defaults of 0s for all grades, percent, and a grade of an F. However, the first argument should (which is the name of the student) should not have a default value, but one should be provided during the allocation of the object. The last constructor, copy, should copy member by member. Be sure to cout a statement (inside the constructors implementation) when each constructor is called.

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 progresses, we will figure out a way to understand and get rid of this warning.

The program has 3 files total. A header file called cgrade.h, where your class should be declared. An implementation file called cgrade.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 HW16 directory.

To help you get started, I went ahead and created a HW16 subdirectory for you and put starter kit in there called CGradeStarterKit.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 CGradeStarterKit.tar.gz 

This will extract the files contained within the archive into the present working directory. You should then find a partially completed main.cpp and cgrade.h files and an executable file. Youll need to fill in the ??? in those files and create the implementation of the functions in a file called cgrade.cpp. To run the example executable is ./GradeCalc

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:

$ ./GradeCalc Default Constructor! Type Constructor! Copy Constructor! The grades of S1 (default constructor): NULL: 0.0%F Info for S1: 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: Elon Musk: 78.5% C Edgar Allen Poe: 0.0% F Edgar Allen Poe: 0.0% F

This is Student Grades

studentGrades.cpp

#include #include #include #include #include using namespace std;

//Structure used for grade struct Grade { char name[80]; double quiz1;

double quiz2;

double midterm; double finalExam; double percent; char grade; };

//function prototypes void GetInfo(Grade &grade); void DispGrade(Grade &grade); void CalcGrade(Grade &grade); void CalcPercent(Grade &grade);

//start of main method int main() {

Grade s1,s2;

cout << "Enter for the first student:" << endl; GetInfo(s1);

cout << "Enter for the second student:" << endl; GetInfo(s2);

CalcGrade(s1); CalcGrade(s2);

cout << "The grades of the students are:" << endl; DispGrade(s1); DispGrade(s2);

return 0; }

// ====GetInfo================================================================= // This gets the information from the user // ============================================================================

void GetInfo(Grade &grade) { cout << "\tEnter student's full name: "; cin.getline(grade.name,80);

cout << "\tEnter Quiz 1 grade (out of 10):"; cin >> grade.quiz1;

cout << "\tEnter Quiz 2 grade (out of 10): "; cin >> grade.quiz2;

cout << "\tEnter midterm grade (out of 100): "; cin >> grade.midterm;

cout << "\tEnter final exam grade (out of 100): "; cin >> grade.finalExam;

cin.ignore(80,' '); }

// ====CalcGrade=============================================================== // This function calculates the grades // ============================================================================

void CalcGrade(Grade &grade) { CalcPercent(grade);

if(grade.percent>=90) grade.grade='A';

else if(grade.percent >=80 && grade.percent<90) grade.grade='B';

else if(grade.percent >=70 && grade.percent<80) grade.grade='C';

else if(grade.percent >=60 && grade.percent<70) grade.grade='D';

else grade.grade='F'; }

// ====CalcPercet============================================================== // This functino calculates the percentage // ============================================================================

void CalcPercent(Grade&grade) {

double q = double(grade.quiz1+grade.quiz2) / 20 * 25.0; double m = double(grade.midterm) / 100 * 25.0; double f = double(grade.midterm) / 100 * 50.0; grade.percent = q + m + f; }

// ====DispGrade=============================================================== // This function displays the grade // ============================================================================

void DispGrade(Grade &grade) { cout << fixed << setprecision(1);

cout << "\t" << grade.name << ":"

<< grade.percent

<< "%" << grade.grade << endl;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

List the types of turnover.

Answered: 1 week ago