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

I need a c++ code for the assignment #13 (pure abstract base class). it is conti

ID: 3721829 • Letter: I

Question




I need a c++ code for the assignment #13 (pure abstract base class). it is continued in the next picture. Don't forget it has to accept values for the various shapes. Thanks!

Cruiseship, and Cargoship objects. (See Program 15-14, lines 17 through 22, for an example of how to do this.) The program should then step through the array, calling each object's print function 13. Pure Abstract Base Class Project 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 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.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

class BasicShape{
private:
    double area; //stores the shape's area
public:
    double getArea(){ //returns the value stored in area variable
      return area;
    }
    void setArea(double area){
      this->area = area;
    }
    virtual void calcArea() = 0; //pure virtual function, this makes the class abstract class
};

class Circle : public BasicShape {
private:
    long int centerX, centerY; //stores the coordinates of the center of the circle
    double radius;//stores the radius of the circle
public:
    Circle(long int centerX, long int centerY, double radius) { //constructs a rectangle
      this->centerX = centerX;
      this->centerY = centerY;
      this->radius = radius;
      calcArea();
    }
    void calcArea(){ //computes the area of the circle using the given formula
      setArea(3.14159 * radius * radius);
    }
};

class Rectangle : public BasicShape {
private:
    long int width, length; //stores the dimensions of the rectangle
public:
    Rectangle(long int width, long int length) { //constructs a rectangle
      this->width = width;
      this->length = length;
      calcArea();
    }
    long int getWidth(){//outputs the width of the rectangle
      return width;
    }
    long int getLength(){//outputs the length of the rectangle
      return length;
    }
    void calcArea(){//computes the area of the rectangle
      setArea(double(width * length));
    }
};
int main() {
long int centerXCircle, centerYCircle;
double radiusCircle;
printf("Enter the center coordinates of the Circle: ");
scanf("%ld%ld",&centerXCircle, &centerYCircle); //scan rectangle's dimensions
printf("Enter the radius of the Circle: ");
scanf("%lf",&radiusCircle);
Circle C = Circle(centerXCircle, centerYCircle, radiusCircle); // construct the circle
printf("Area of the circle is %lf ",C.getArea());

long int rectangleLength, rectangleWidth;
printf("Enter the length and width of the Rectangle: ");
scanf("%ld%ld",&rectangleLength, &rectangleWidth); //scan rectangle's dimensions
Rectangle R = Rectangle(rectangleLength, rectangleWidth); //construct the rectangle
printf("Area of the rectangle is %lf ",R.getArea());
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