Question: IN C++ 1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors for each

IN C++

1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors for each derived class should error check that the input argument points form a valid shape of the given type and offer an error message to the user if invalid.

IN C++ 1. Create a base class Polygon from which several other

Triangle and parallelogram areas are bh and bh, respectively, where the height at point (x0,y0) is

classes of shapes are derived according to the figure below. Constructors for

with the base passing through points (x1,y1) and (x2,y2). The following header file is provided but the implementations of each member function must be completed. Additional member functions can be added as desired. Class functionality is then tested with the included main function. Extra credit is awarded if the data member array of points vertex is dynamically allocated.

Shapes.h header file with class prototypes:

#include "Point.h"

#include

using namespace std;

class Polygon {

protected:

Point vertex[10];

int numPoints;

string shapeName;

public:

Polygon();

void setPoints (double x[], double y[], int numP);

// Writes shapeName and all vertices to the screen

void displayPoints();

double getPerimeter ();

};

class Triangle : public Polygon {

public:

Triangle(double x1, double y1, double x2, double y2, double x3, double y3);

double getArea();

};

class EquilateralTriangle : public Triangle {

public:

// Displays error if given points do not make equilateral triangle

EquilateralTriangle(double x1, double y1, double x2, double y2,

double x3, double y3);

};

class RightTriangle : public Triangle {

public:

// Displays error if given points do not make right triangle

RightTriangle(double x1, double y1, double x2, double y2,

double x3, double y3);

};

class Parallelogram : public Polygon {

public:

// Displays error if given points do not make parallelogram

Parallelogram(double x1, double y1, double x2, double y2,

double x3, double y3, double x4, double y4);

double getArea();

};

class Rectangle : public Parallelogram {

public:

// Displays error if given points do not make rectangle

Rectangle(double x1, double y1, double x2,

double y2, double x3, double y3, double x4, double y4);

};

Main CPP file for testing:

#include

#include "Shapes.h"

using namespace std;

int main() {

EquilateralTriangle tri1(0,0 , 0.5,0.5 , 1,0),

tri2(0,0 , 0.5,0.8660254 , 1,0);

tri2.displayPoints();

cout

cout

RightTriangle right1(0,0 , 1,1 , 3,0 ),

right2(0,0 , 0,1 , 3,0.5),

right3(0,0 , 0,1 , 3,0 );

right3.displayPoints();

cout

cout

Parallelogram par1(1,0 , 2.1,1 , 4,1 , 3,0),

par2(1,0 , 2,1 , 3.8,1 , 3,0),

par3(1,0 , 2,1 , 4,1 , 3,0);

par3.displayPoints();

cout

cout

Rectangle rect1(1,0 , 2,1 , 4,1 , 3,0),

rect2(1,0 , 2.1,1 , 4,1 , 3,0),

rect3(0,0 , 0,3 , 4,3 , 4,0);

rect3.displayPoints();

cout

cout

return 0;

}

each derived class should error check that the input argument points form

Polygon Triangle Parallelogram Right Triangle Equilateral Triangle Rectangle riangle is not equilateral Points for equilateral triangle: (0.0> 0 . 5 , 0 . 866025) 1.0) A -0.433013 riangle is not right riangle is not right Points for right triangle: 0.0) (0.1 P7.16228 =1.5 Opposite sides are not parallel pposite sides are not parallel Points for parallelogran: K1.0> K2.1) K4.1 3.0) P-6.82843 Angles not right pposite sides are not parallel Points for rectangle: 0.0> K4.3) C4.8) P=14 A12 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!