Question: Define an abstract base class called BasicShape. The BasicShape class should have the following members: ( Reference: Fig 1 2 . 9 and 1 2
Define an abstract base class called BasicShape. The BasicShape class should have the following members: Reference: Fig and
a Protect Member Variable: area a double used to hold the shape's area
b Private Member Variable: name a string to indicate the shape's type
c Constructor and Public Member Functions:
BasicShapedouble a string n: A constructor that sets value of member area with a and member name with
calcArea : This public function should be a pure virtual function.
print: A public virtual function that only prints the value of data member area
getName:A public function that returns the value of data member name
Define a class named Circle. It should be derived from the BasicShape class. It should have the following members: Reference: Fig and
a Private Member Variable: radius a double used to hold the circle's radius
b Constructor and Public Member Functions:
Circledouble a string double : constructor that should call the base class constructor to initialize the member area with a and name with The constructor will also set the value of member radius with
calcArea : Overridden function that calculates the area of the circle 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.
After you have created these classes, create a test program Reference: Fig
Write a function named poly whose only parameter is a BasicShape pointer.
Function poly should use the BasicShape pointer to invoke calcArea function and print function.
In main : define a Circle object with initial area name Round and radius
From main call the function poly such that it will polymorphically ie using a pointer of the base class invoke calcArea function and print function of the Circle object
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
