Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer in C++ please. 1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors

image text in transcribedimage text in transcribedimage text in transcribedAnswer in C++ please.

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. Polygon Triangle Parallelogram Right Triangle Equilateral Triangle Rectangle Triangle and parallelogram areas are lbh and bh, respectively, where the height at point (xo.yo) is h V. - y)xo - (x1 - x)) + X: - VX VW- )+(x - x; with the base passing through points (x1y) and (x2y2). 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 xil, double yll, int num); // Writes shapeName and all vertices to the screen void displaypoints(); double getPerimeter (); }; 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 x1, 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 xl, double yi, 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 yi, double x2, double y2, double x3, double y3, double x4, double y4); 2 ) > 2.1,1 7.16228 Main CPP file for testing: #include #include "Shapes.h" using namespace std; int main() { EquilateralTriangle 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 setPoints (double xil, double yll, int num); // Writes shapeName and all vertices to the screen void displaypoints(); double getPerimeter (); }; 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 x1, 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 xl, double yi, 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 yi, double x2, double y2, double x3, double y3, double x4, double y4); 2 ) > 2.1,1 7.16228 Main CPP file for testing: #include #include "Shapes.h" using namespace std; int main() { EquilateralTriangle tril(0,0 0.5, 0.5 1,0), tri2(0,0, 0.5, 0.8660254 1,0); tri2.displayPoints(); cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions