Question: Define a pure abstract base class called BasicShape. The BasicShape class should have the following members: Private Member Variable: area, a double used to hold
Define a pure abstract base class called BasicShape. The BasicShape class should have the following members: Private Member Variable:
- area, a double used to hold the shapes area.
Public Member Functions:
- getArea. This function should return the value in the member variable area.
- calcArea. This function should be a pure virtual function.
Next, define a class named Circle. It should be derived from the BasicShape class. It should have the following members: Private Member Variables:
- centerX, a long integer used to hold the x coordinate of the circles center.
- centerY, a long integer used to hold the y coordinate of the circles center.
- radius, a double used to hold the circles radius.
Public Member Functions:
- constructoraccepts values for centerX, centerY, and radius. Should call the overridden calcArea function described below.
- getCenterXreturns the value in centerX.
- getCenterYreturns the value in centerY.
- calcAreacalculates the area of the circle (area = 3.14159 * radius * radius) and stores the result in the inherited member area.
Next, define a class named Rectangle. It should be derived from the BasicShape class. It should have the following members: Private Member Variables:
- width, a long integer used to hold the width of the rectangle.
- length, a long integer used to hold the length of the rectangle.
Public Member Functions:
- constructoraccepts values for width and length. Should call the overridden
- calcArea function described below.
- getWidthreturns the value in width.
- getLengthreturns the value in length.
- calcAreacalculates the area of the rectangle (area = length * width) and stores the result in the inherited member area.
After you have created these classes, create a driver program that defines an area of Shape pointers that holds a Circle object and a Rectangle object. Demonstrate that each object properly calculates and reports its area.
I was given the driver.cpp file:
#include "BasicShape.h" #include "Circle.h" #include "Rectangle.h"
#include
int main() { BasicShape * shapes[4]; shapes[0] = new Circle(3,4,5); shapes[1] = new Circle(2,1,2.3); shapes[2] = new Rectangle(3,4); shapes[3] = new Rectangle(13,2); for(int i = 0; i < 4; ++i) { shapes[i]->calcArea(); cout << "Area: " << shapes[i]->getArea() << endl; } return 0; }
Now I just need the circle.h file, circle.cpp file, BasicShape.cpp file, BasicShape.h file, Recantangle.cpp file, and Rectangle.h file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
