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

2: Define a class named Circle. It should be derived from the BasicShape class.

ID: 3777092 • Letter: 2

Question

2:   

Define a class named Circle. It should be derived from the BasicShape class.

It should have the following members:

a) Private Member Variable: radius (a double used to hold the circle’s radius)

b) Constructor and Public Member Functions:

Circle(double a, string n, double r): constructor that should call the base class

constructor to initialize the member area with a and name with n. The constructor

will also set the value of member radius with r

calcArea(): Overridden function that calculates the area of the circle (area =

3.14159 * radius * radius) and stores the result in the inherited member area.

print(): Overridden function that will print the radius, inherited member area and

inherited member name. This function should use the base class’s print function

to print the area.

Explanation / Answer

Here is the code for you:


//Define a class named Circle. It should be derived from the BasicShape class.
class Circle:BasicShape
{
//a) Private Member Variable: radius (a double used to hold the circle’s radius)
private:
double radius;
public:
//Circle(double a, string n, double r): constructor that should call the base class
//constructor to initialize the member area with a and name with n. The constructor
//will also set the value of member radius with r
Circle(double a, string n, double r) : BasicShape(a, n)
{
radius = r;
}
//calcArea(): Overridden function that calculates the area of the circle (area =
//3.14159 * radius * radius) and stores the result in the inherited member area.
void calcArea()
{
area = 3.14159 * radius * radius;
}
//print(): Overridden function that will print the radius, inherited member area and
//inherited member name. This function should use the base class’s print function
//to print the area.
void print()
{
cout<<"Radius = "<<radius<<endl;
cout<<"Shape ="<<getName()<<endl;
BasicShape::print();
}
};

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