Question: Start with the code below. Remove the constructor functions. Now create two derived classes from the Student class by using public inheritance. The names of

Start with the code below. Remove the constructor functions. Now create two derived classes from the Student class by using public inheritance. The names of the derived classes are Freshman and Senior.

The Freshman class needs to have:

A private variable called csce1030 to store CSCE 1030 score. Accessor function called getValue and mutator function called setValue to access and change the CSCE1030 score. The accessor function must be of void return type. The mutator function needs to prompt the user for the value for the score.

The Senior class needs to have A private variable called csce4530 to store CSCE 4530 score. Accessor function called getValue and mutator function called setValue to access and change the CSCE4530 score. The accessor function must be of void return type. The mutator function needs to prompt the user for the value for the score.

The base class has the same functions, so call the base class function from the derived class function.

In the main function:

Create one object each of type Freshman and Senior. Call the derived class accessor and mutator functions to set and get the value of name, id, gpa and respective scores.

#include #include using namespace std;

class Student { public: Student(); Student(unsigned long int id, string name, double gpa); void setVars(); void getVars(); private: unsigned long int id; string name; double gpa; };

Student::Student()//default constructor { id = 0; name = " "; gpa = 0.0; }

Student::Student(unsigned long int id, string name, double gpa)//argument constructor { this->id = id; this->name = name; this->gpa = gpa; }

void Student::setVars() // mutator { unsigned long int id; string name; double gpa; cout<<" Enter the value of id : "; cin>>id; this->id= id; cout<<" Enter the value of name : "; getline(cin,name); this->name=name; cout<<" Enter the value of gpa : "; cin>>gpa; this->gpa=gpa; }

void Student::getVars() //accessor { cout<<" ID : "<

int main() { Student student1(12345678, "First Last", 4.0); cout<<" Student 1: "; student1.getVars();

Student student2;

student2.setVars(); cout<<" Student 2: "; student2.getVars();

return 0; }

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!