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 circle s center.
centerY, a long integer used to hold the y coordinate of the circle s center.
radius, a double used to hold the circle s radius.
Public Member Functions:
constructor accepts values for centerX, centerY, and radius. Should call the
overridden calcArea function described below.
getCenterX returns the value in centerX.
getCenterY returns the value in centerY.
calcArea calculates 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:
constructor accepts values for width and length. Should call the overridden
calcArea function described below.
getWidth returns the value in width.
getLength returns the value in length.
calcArea calculates 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.
Starter: lab14_ex1_starter.cpp
Submit: lab14_ex1.cpp
lab14_ex1_starter.cpp is
// Chapter 13, Programming Challenge 13: Pure Abstract Base Class 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
using namespace std;
class BasicShape
{
};
class Circle : public BasicShape
{
};
class Rectangle : public BasicShape
{
};
int main()
{
long x, y, length, width;
double rad;
// Demonstrate a Circle.
cout << "Please enter the x coordinate of the circle's center: ";
cin >> x;
cout << "Please enter the y coordinate of the circle's center: ";
cin >> y;
cout << "Please enter the radius of the circle: ";
cin >> rad;
Circle c(x,y,rad);
cout << "The area of the circle is " << c.getArea() << ".";
// Demonstrate a Rectangle.
cout << "nnPlease enter the length of the rectangle: ";
cin >> length;
cout << "Please enter the width of the rectangle: ";
cin >> width;
Rectangle r(width, length);
cout << "The area of the rectangle is " << r.getArea() << ".n";
return 0;
}