Inheritance

Okay I am having a hard time learning c++ and i think i have this code mostly done i just dont know how to finish it off. Any help would be appreciated.

Given a parent class below (Student), derive a child class (UndergradStudent).
The UndergradStudent should have two new members: float engScore, float bioScore.The UndergradStudent should overwrite getGPA() to take into consideration of two new members.In the main function, create one object of Student and another object of UndergradStudent and let the two objects to call their own getGPA().


#include <iostream>
using namespace std;

class Student
{
protected:
int ID;
float mathScore;
float chemScore;
public:
Student (int = 0, float = 0.0f, float = 0.0f);
void getGPA();
};

Student::Student (int id, float ms, float cs)
{
ID = id;
mathScore = ms;
chemScore = cs;
}

void Student::getGPA ()
{
float gpa = (mathScore + chemScore)/2.0;
cout << "ID = " << ID << " PGA = " << gpa << endl;
}
class UndergradStudent : public Student
{
protected:
float engScore;
float bioScore;
public:
Student(int id = 0, float ms = 0.0, float cs = 0.0, float es = 0.0, float bs = 0.0) : Student(id), mathScore(ms), chemScore(cs),
engScore(es), bioScore(bs) {}
void getGPA();
};

void UndergradStudent::getGPA ()
{
float gpa = (mathScore + chemScore + engScore + bioScore)/4.0;
cout << "ID = " << ID << " PGA = " << gpa << endl;
}
int main()
{


> i just dont know how to finish it off.
really?

1
2
3
4
5
6
7
8
9
10
int main()
{
    Student student = Student(777,70.5,99.8);
    UndergradStudent underStudent = UndergradStudent(999,80,55.6,70,44.9);

    student.getGPA();
    underStudent.getGPA();

   return 0;
}
Topic archived. No new replies allowed.