Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Derive a child class of GradStudent by treating Student as a parent class. New d

ID: 3765216 • Letter: D

Question

Derive a child class of GradStudent by treating Student as a parent class. New data member: Physics score. New function members: (1) A default constructor of no-argument, and another constructor that accepts actual arguments; Override the compAveScore () function to take into account Physics score: average score = (Mathematics score + Chemistry score + Physics score)/3.0 In the main function, test the Student and GradStudent classes as follows: Declare an empty vector. Add two Student objects to the vector: a ("Bob", 60, 70) and b ("John", 70, 80). Add two GradStudent objects to the vector: c ("Janet", 77, 88, 99) and d("Marie", 82, 92, 99). Loop through all objects using an iterator, print out names and average scores (call compAveScore ()) such as: Bob 65 John 75 Janet 88 Marie 91

Explanation / Answer

#include<iostream>
#include<vector>
#include<conio>
#include<string>
using namespace std;
class Student
{
public:
   double math, che;
   char name[20];
   Student()
   {
   }
   Student(char n[20], double m, double c)
   {
       strcpy(name,n);
       math=m;
       che=c;
   }

   void compAveScore()
   {

       double av=(math+che)/2.0;
       cout<<name<<" "<<av<<endl;

   }

};

class GradStudent : public Student
{
public:
   double phy;
   GradStudent()
   {
       phy=0;
   }

   GradStudent(char n[20],double p, double m, double c)
   {
       strcpy(name,n);
       phy=p;
       math=m;
       che=c;
   }

   void compAveScore()
   {
       double av=(phy+math+che)/3.0;
       cout<<name<<" "<<av<<endl;
   }
};

void main()
{
   int i;
   vector<Student> v1;
   vector<GradStudent> v2;
   v1.push_back(a("Bob",60,70));
   v1.push_back(b("John",70,80));
   v2.push_back(c("Janet",77,88,99));
   v2.push_back(d("Marie",82,92,99));

   for(i=0;i<2;i++)
   {
       v1[i].compAveScore();
   }

   for(i=0;i<2;i++)
   {
       v2[i].compAveScore();
   }
   getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote