Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a polygon class to calculate the area for a given shape up to 4 sides. In

ID: 3565874 • Letter: C

Question

create a polygon class to calculate the area for a given shape up to 4 sides.   

Inputted Value: 5, 6, 5, and 6

Inputted Value: 3, 3, 3, and 3

Inputted Value: 3, 4, 5, and 0 (zero denotes no side.)

assume all inputs are valid the inputted object will always be a square, rectangle, or triangle.

create a polygon class to calculate the area for a given shape up to 4 sides. Define a new class called ?Polygon?, which will store the length of each side (in decimal) up to 4. Make sure the data are kept private. You will need to create setter and getter functions to retrieve or assign values from these variables. Create a new enumeration type called Shape, which defines if the object is a Triangle, Square, and Rectangle. Create a ShapeValidator() function (within the Polygon class) to determine if the object is a triangle, a square or a rectangle. For example, if entered ? 3, 4, 5, and 0 then this is a triangle. Any unused side will be denoted as zero (0) during input. Please use Shape as the returned data type. Create an Area() function (within the Polygon class) to calculate the area of an object. Use the ShapeValidator() function to determine which formula to use. Use the guide below to calculate the area: 5. Create a main function to utilize the Polygon class to determine the shape, area, and volume for a given object. allow users to input the different sides. (C++ syntax only) Use the sample screenshots below as a guide: Inputted Value: 5, 6, 5, and 6 Inputted Value: 3, 3, 3, and 3 Inputted Value: 3, 4, 5, and 0 (zero denotes no side.) assume all inputs are valid ? the inputted object will always be a square, rectangle, or triangle.

Explanation / Answer

typedef struct Point

{

double X;

double Y;

Point()

{

X = 0;

Y = 0;

}

Point(double x, double y)

{

X = x;

Y = y;

}

} Point;

class SimplePolygon

{

protected:

int _nsides;

Point* _vertices;

public:

SimplePolygon(int nsides)

{

_nsides = nsides;

_vertices = new Point[nsides];

}

~SimplePolygon()

{

delete[] _vertices;

}

Point GetVertex(int idx)

{

return _vertices[idx];

}

void SetVertex(int idx, Point point)

{

_vertices[idx] = point;

}

};

class Triangle : public SimplePolygon

{

public:

Triangle(Point a, Point b, Point c)

: Polygon(3)

{

SetVertex(0, a);

SetVertex(1, b);

SetVertex(2, c);

}

};