Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MTRE 2610 - Engineering algorithms and visualization - Dr. Kevin McFall Homework - Inheritance 1. Create a base class Polygon from which several other classes
MTRE 2610 - Engineering algorithms and visualization - Dr. Kevin McFall 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. Polygon Triangle Parallelogram Right Triangle Equilateral Triangle Rectangle Triangle and parallelogram areas are 2bh and bh, respectively, where the height at point (x0.yo) is h = |(y2 yi ) X -(x3 x) y + x3y1 - y23|| (yz - y)2+(x3 17 ) with the base passing through points (x1.y) 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 "Reintih" #include using namespace std; class Polygon { protected: Point vertex[10]; int numPoints; string shapeName; public: Polygon(); void setpaints (double x[], double yll, int nume); // Writes shapeName and all vertices to the screen void displaypoints(); double getPerimeter (); class Triangle : public Polygon { public: Triangle (double x1, double yi, double x2, double y2, double x3, double y3); double getArea(); }; class Eguilateral Triangle : public Triangle { public: // Displays error if given points do not make equilateral triangle EquilateralTriangle (double x1, double yi, double x2, double y2, double x3, double y3); }; class Right Triangle : 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 v2, 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); Main CPP file for testing: #include #include "Shareab" using namespace std; int main() { Eauilateral Triangle tril(0,0 , 0.5,0.5 tri2(0,0 , 0.5, 0.8660254, 1,2) tri2.displayPoints(); cout using namespace std; class Polygon { protected: Point vertex[10]; int numPoints; string shapeName; public: Polygon(); void setpaints (double x[], double yll, int nume); // Writes shapeName and all vertices to the screen void displaypoints(); double getPerimeter (); class Triangle : public Polygon { public: Triangle (double x1, double yi, double x2, double y2, double x3, double y3); double getArea(); }; class Eguilateral Triangle : public Triangle { public: // Displays error if given points do not make equilateral triangle EquilateralTriangle (double x1, double yi, double x2, double y2, double x3, double y3); }; class Right Triangle : 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 v2, 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); Main CPP file for testing: #include #include "Shareab" using namespace std; int main() { Eauilateral Triangle tril(0,0 , 0.5,0.5 tri2(0,0 , 0.5, 0.8660254, 1,2) tri2.displayPoints(); cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started