Abe K.

asked • 04/14/21

Implement an abstract parent Shape class and its polymorphic children Circle, Rectangle, and Triangle. 

Your objective for this project is to implement an abstract parent Shape class and its polymorphic children CircleRectangle, and TriangleShape is a 2D character array which requires the use of dynamic memory allocation, and its children are their eponymous shapes held character-by-character within that 2D array. Additionally, each shape is represented by its perimeter populated by ASCII characters within the range [48, 126] in order, and character choice from this range wraps around back to 48 when 127 is reached. In order to successfully complete this project, you must understand the prerequisite material from the previous projects, and you must understand the concepts of 2D arrays, abstract classes, polymorphism, and basic shape manipulations.


Task 1

Define and implement the abstract class Shape, which contains the following methods:

// Parameterized Constructor; there is no default constructor
Shape(const int &width, const int &height);

// Getters
int getEdges();
int getWidth();
int getHeight();
char **getDisplayChars();
// Setters
void setEdges(const int& edges);
void setWidth(const int& new_width);
void setHeight(const int &new_height);
void setDisplayChars(char **display);

// Mutators
void rotateRight(); //rotate by 90 degrees
void rotateLeft(); //rotate by 90 degrees
void reflect(char axis); //reflect over x or y axis
// Pure Virtual Methods (no implementation)
virtual double getSurfaceArea() = 0;
virtual double get3DVolume(const double& depth) = 0;

// Display - //iterate through 2D array and print chars
void display();

Note:

  1. reflect() takes the parameter 'x' or 'y'.
  2. getSurfaceArea() uses the canonical formulae for surface area given each respective shape.
  3. get3DVolume() yields the volume of the caller shape if it was projected into 3 dimensions using the depth parameter as the z-axis value. For a circle, this function yields the volume of the related sphere. For a rectangle, this function yields the volume of the related rectangular cuboid. For a triangle, this function yields the volume of the related right triangular prism, since Triangle only considers right triangles. Use the canonical formulae for volume given each respective surface.


1 Expert Answer

By:

Patrick B. answered • 04/14/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Abe K.

This is the link containing all the instructions for the project and images on how the characters are displayed: https://maryash.github.io/235/projects/project-4/project-4.html
Report

04/15/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.