Homework - Inheritance 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. Polygo Triangl Parallelo Right Equilat Rectan Triangt eral Tri g te Triangle and parafilogram areas are where the height at point (x) is bh and bh, respectively, .- - with the base passing through points (xy) and (xy). 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 set Points (double x[], double y[], int numP); // Writes shapeName and all vertices to the screen void display Points(); double get Perimeter (); class Triangle : public Polygon { public: Triangle (double xl, double yi, 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 xl, double yi, 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 xl, double yi, 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 yi, double x2, double y2, double x3, double y3, double x4, double y 4); double getArea(); class Rectangle : public Parallelogram { public: // Displays error if given points do not make rectangle Rectangle (double xl, double yi, 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() { Equilateral Triangle tril(0,0,0.5.0.5 , 1.0), tri2(0.0, 0.5,0.8660254, 1,0); tri2.displayPoints(): cout using namespace std; class Polygon { protected: Point vertex [10]; int numPoints; string shapeName; public: Polygon(); void set Points (double x[], double y[], int numP); // Writes shapeName and all vertices to the screen void display Points(); double get Perimeter (); class Triangle : public Polygon { public: Triangle (double xl, double yi, 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 xl, double yi, 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 xl, double yi, 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 yi, double x2, double y2, double x3, double y3, double x4, double y 4); double getArea(); class Rectangle : public Parallelogram { public: // Displays error if given points do not make rectangle Rectangle (double xl, double yi, 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() { Equilateral Triangle tril(0,0,0.5.0.5 , 1.0), tri2(0.0, 0.5,0.8660254, 1,0); tri2.displayPoints(): cout