Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE WRITE FULL CODE IN C++ Define a pure abstract base class called BasicShap

ID: 3693591 • Letter: P

Question

PLEASE WRITE FULL CODE IN C++

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: centre, a long integer used to hold the x coordinate of the circle s centre century, a long integer used to hold the y coordinate of the circle s centre radius, a double used to hold the circles radius. Public Member Functions: constructor-accepts values for Centrex, century, and radius. Should call the overridden calcArea function described below. Get Centrex-returns the value in Centrex. Get Century-returns the value in century. 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. get width-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.

Explanation / Answer

/** C++ having BasicShape , Circle, Rectangle class and find their Area **/

#include <iostream>
using namespace std;

class BasicShape{
protected:
double area;
public:
double getArea()
{
return area;
}

virtual void calcArea() = 0;
};

class Circle: public BasicShape{
private:
double centerX;
double centerY;
double radius;
public:
Circle()
{
centerX = 0;
centerY = 0;
radius = 0;
calcArea();
}

//circle constructor
Circle(double X, double Y, double r)
{
centerX = X;
centerY = Y;
radius = r;
calcArea();
}

//get methods
double getCenterX()
{
return centerX;
}
  
double getCenterY()
{
return centerY;
}

//area finder
void calcArea()
{
area = 3.14159 * radius * radius;
}
};

  
class Rectangle: public BasicShape{
private:
double width;
double length;
public:
//rectangle constructor
Rectangle(double l,double w)
{
length =l;
width=w;
calcArea();
}

//get methods
double getWidth()
{
return width;
}

double getLength()
{
return length;
}

//area finder
void calcArea()
{
area=length*width;
}
};


int main()
{
//create an object for circle
Circle c(2,2,2);
//create an object for Rectangle
Rectangle r(10,5);

//Display circle object data
cout << "Circle " << endl;
cout << "Center x: " <<c.getCenterX()<<endl;
cout << "Center y: " <<c.getCenterY()<<endl;
cout << "Area : " <<c.getArea()<<endl<< endl;

//Display Rectnagle object data
cout << "Rectangle " <<endl;
cout << "Length : " <<r.getLength()<<endl;
cout << "Width : " <<r.getWidth() <<endl;
cout << "Area : " <<r.getArea() <<endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote