Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework - Inheritance 1. Create a base class Polygon from which several other classes of shapes are derived according to the figure below. Constructors for

image text in transcribed
image text in transcribed
image text in transcribed
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

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_2

Step: 3

blur-text-image_3

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

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions