PROGRAMMING EXERCISES 32. In the file \"grade.h,\"give the C++ declaration and i
ID: 3869820 • Letter: P
Question
PROGRAMMING EXERCISES 32. In the file "grade.h,"give the C++ declaration and implementation of the grade Record class from Written Exercise 1-14. (a) Write a program that declares the gradeRecord object tMarin with initial values 716-29-4238" (studentID), 20 (units), and 50 (gradepts). Output the initial GPA After completing the semester, the student represented by object tMartin adds 15 units and 40 grade points. Update the grade record, and output the new grade-record information (b) Write a program that declares the following objects: grade Record aDunn( 455-27.9138", 14,49), bLange "67-58-0331",25,50); Output the gpa for both aDunn and bLange.Assume aDunn completes 4 units with a grade of A (16 gradepoints). Update the corresponding grade record, and output the new grade-record information. Assume blange takes 15 units in a semester. In a loop, determine the effect on the total GPA if the average grade for the 15 units is a C (two gradepts per unit), a B (three gradepts per unit), and an A (four gradepts per unit). Output the total GPA for each case.Explanation / Answer
Hi, please refer to this code made in Xcode.
I have added comments for your easy understanding
Header file's data
#include <iostream>
using namespace std;
class gradeRecord
{
string studentID;
int units;
float gradepts;
public:
//default constructor
gradeRecord()
{
studentID=' ';
units=0;
gradepts=0;
}
//parameterised constructor
gradeRecord(string a, int b, float c)
{
studentID=a;
units=b;
gradepts=c;
}
//if we want to update the record, we can use this
void update(string a, int b, float c)
{
studentID=a;
units+=b;
gradepts+=c;
}
//if we want to remove marks from the record, we can use this
void unupdate(string a, int b, float c)
{
studentID=a;
units-=b;
gradepts-=c;
}
//this is to print the data
void display()
{
cout<<"StudentID: "<<studentID<<endl;
cout<<"Units: "<<units<<endl;
cout<<"GradePoints: "<<gradepts<<endl;
}
//this will reutrn the gpa
float gpa()
{
return gradepts/units;
}
};
Part a:
int main()
{
gradeRecord tMartin("716-29-4238",20,50);
cout<<"Initital GPA: "<<tMartin.gpa()<<endl;
tMartin.update("716-29-4238",15,40);
cout<<"Final GPA: "<<tMartin.gpa()<<endl;
return 0;
}
Output:
Initital GPA: 2.5
Final GPA: 2.57143
Part B:
int main()
{
gradeRecord aDunn("455-27-9138",20,50);
gradeRecord bLange("657-58-0331",25,50);
cout<<"Initital GPA of aDunn: "<<aDunn.gpa()<<endl;
cout<<"Initial GPA of bLange: "<<bLange.gpa()<<endl;
aDunn.update("455-27-9138",4,16);
cout<<"Final GPA of aDunn: "<<aDunn.gpa()<<endl;
for(int i=2;i<5;i++)
{
bLange.update("657-58-0331", 15, i*15);
cout<<"GPA of bLange with "<<i<<" gradepts per unit: "<<bLange.gpa()<<endl;
bLange.unupdate("657-58-0331", 15, i*15);
}
return 0;
}
Output
Initital GPA of aDunn: 2.5
Initial GPA of bLange: 2
Final GPA of aDunn: 2.75
GPA of bLange with 2 gradepts per unit: 2
GPA of bLange with 3 gradepts per unit: 2.375
GPA of bLange with 4 gradepts per unit: 2.75
If you face any issue with this, you can leave a comment.
If you find this helpful, then please dont forget to leave a thumbs up, thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.