Question
This is what I have so far, I need help completing the program. Define a pure abstract base class called BasicShape . The BasicShape class
This is what I have so far, I need help completing the program.
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 shape's 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 circle's 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 a Circle object and a Rectangle object. Demonstrate that each object properly calculates and reports its area.
Files Required to be submitted for this assignment: PureAbstractBaseClass.cpp BasicShape.h Circle.h
Rectangle,h
This program should be used to test your project
// Driver program is used to test the BasicShape (Abstract Base Class), Circle // (Derived Class) and Rectangle (Derived class). // The program asks for needed information for both a circle and rectangle and // returns the area.
#include #include "Circle.h" #include "Rectangle.h" using namespace std;
int main() {
}
long xCoordinate, yCoordinate, length, width; double rad;
// Demonstrate a Circle.
cout > xCoordinate; cout > yCoordinate;
cout > rad; Circle Circle(xCoordinate, yCoordinate, rad); cout
// Demonstrate a Rectangle.
cout > length; cout > width;
Rectangle rectangle(width, length); cout
Program Output: Please enter the x coordinate of the circle's center: 23
Please enter the y coordinate of the circle's center: 23 Please enter the radius of the circle: 5 The area of the circle is 78.5397.
Please enter the length of the rectangle: 23 Please enter the width of the rectangle: 44 The area of the rectangle is 1012.
Press any key to continue . . .
pragma once #include "BasicShape.h" #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started