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

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.

Solution

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();
}
};

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 doub

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site