Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ 2. Define the class GradStudent that is derived from the class Student . The GradStudent has a private data member gradFee (double). a.

In c++

2.

Define the class GradStudent that is derived from the class Student. The GradStudent has a private data member gradFee(double).

a. Define a default constructor as well as a constructor with parameters for the class GradStudent.

b. The class must have get and set functions for private data member gradFee.

c. Redefine the function tuition (double feePerUnit) that computes and returns the cost of registering for the number of units (in the private data member). This function must call the tution() function in the base class and add the gardFee to it.

d. Overload the operator insertion (<<) for the GradStudent to display student name, age and gradFee.

e. Test the class GradStudent, the overloaded operator (<<) and the tuition function (pass 100 as feePerUnit) similar to the student class.

#include

#include

using namespace std;

class Student

{

private:

string name;

int age;

int units;

public:

Student() { //Default Constructor

cout << "This is default constructor.";

}

Student(string name, int age, int units) { //Parameterized Constructor

this->name = name; /*Assign value of name to the class variable, you can also set it with setter method set_name() */

this->age = age; //Assign value of age to the class variable

this->units = units; //Assign value of age to the class variable

cout << "This is default Parameterized constructor.";

}

void set_name(string name) {

this->name = name;

}

string get_name() {

return this->name;

}

void set_age(int age) {

this->age = age;

}

int get_age() {

return this->age;

}

void set_units(int units) {

this->units = units;

}

int get_units() {

return this->units;

}

double tution(double feePerUnit) {

return this->get_units()*feePerUnit; //Total fee= units* feePerUnit

}

void print() {

cout << "Student Info: Name: " << this->get_name();

cout << "Age: " << this->get_age();

cout << "Units: " << this->get_units();

cout << "Cost of tution: " << this->tution(100);

}

};

int main()

{

Student student1("Tim", 20, 5); //Create object of student class with parameterized constructor

student1.print(); //call the print method of student class

system("pause");

return 0;

}

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

3. A scholarship-holders base.

Answered: 1 week ago