Question: this is my draft, please edit and correct the program C++ void polyArea(polygon &thepoly, double *area); double a, b, c, s; void showPoly(polygon &p) {

this is my draft, please edit and correct the program C++
void polyArea(polygon &thepoly, double *area);
double a, b, c, s;
void showPoly(polygon &p)
{
for (unsigned i = 0; i, p.numSides; i++)
showPoint(p.v[i]);
}
int main()
{
polygon poly;
poly.numSides = 0;
cout
for (;;)
{
// Read in the next point. Terminate on done.
cout
getPoint(poly.v[poly.numSides]);
if (!poly.v[poly.numSides].defined)
break;
// update the polygon size.
++poly.numSides;
// If the polygon is full, say so and stop taking input.
if (poly.numSides >= MaxSides)
{
cout
break;
}
}
// Make sure that the polygon is valid.
if (poly.numSides, MinSides)
{
cout
return 0;
}
// The definition is valid, show the definition.
cout
for (unsigned i = 0; i
showPoint(poly.v[i]);
// compute and displlay the circumfernce
cout
// compute and display areas of the polygon and embdded triangles.
// area[0] gives the area of the polygon and embedded triangles.
// area[i] (i > 0) gives the area of the i'th embedded triangle.
double area[MaxSides + 1];
polyArea(poly, area);
cout
// Number of embedded triangles
const unsigned numTriangles = poly.numSides - 2;
for (unsigned i = 1; i
cout
return 0;
}
Convex Polygons Your objective in this assignment is to write a program to compute the circumference and area of an arbitrary convex polygon with three or more sides. Specifically, your program should do the following 1. Accept from the keyboard the definition of a polygon. The polygon is entered, one vertex at a time with each vertex defined as a point in Cartesian coordinates (x, y). See the sample run below. 2. Display the polygon definition as a table of (x, y) points. 3. Display the circumference of the polygon. 4. Display the area of the entire polygon, as well as the area of each of the polygon's component triangles. Note that for a polygon having "n sides, the area is the sum of the areas of "n-2" triangles as shown in the figure below The area of each triangle may be computed from the formula: adh d c re the sides of the triangle. a+b+ c AS-(-s -b-(s-o where sbt of the 3 (xi, yi) Ai (o yo)s Az Aj As (xs, ys) ENTER A POLYGON DEFINITION: Enter next point: 0 70 Enter next point: 50 90 Enter next point: 80 80 Enter next point: 90 40 Enter next point: 60 10 S Enter next point: 10 20 A Enter next point: -1 A negative x coordinate terminates Here is the polygon definition: P (o, 70) L (50, 90) (80, 80) (90, 40) (60, 10) R (10, 20) circumference 271.112 NI Polygon Area 5200 Triangle 1: Area 550 Triangle 2: Area 1650 Triangle 3: Area 1800 Triangle 4: Area 1200 8/22/2018-gpe Page 1/4 Convex Polygons Your objective in this assignment is to write a program to compute the circumference and area of an arbitrary convex polygon with three or more sides. Specifically, your program should do the following 1. Accept from the keyboard the definition of a polygon. The polygon is entered, one vertex at a time with each vertex defined as a point in Cartesian coordinates (x, y). See the sample run below. 2. Display the polygon definition as a table of (x, y) points. 3. Display the circumference of the polygon. 4. Display the area of the entire polygon, as well as the area of each of the polygon's component triangles. Note that for a polygon having "n sides, the area is the sum of the areas of "n-2" triangles as shown in the figure below The area of each triangle may be computed from the formula: adh d c re the sides of the triangle. a+b+ c AS-(-s -b-(s-o where sbt of the 3 (xi, yi) Ai (o yo)s Az Aj As (xs, ys) ENTER A POLYGON DEFINITION: Enter next point: 0 70 Enter next point: 50 90 Enter next point: 80 80 Enter next point: 90 40 Enter next point: 60 10 S Enter next point: 10 20 A Enter next point: -1 A negative x coordinate terminates Here is the polygon definition: P (o, 70) L (50, 90) (80, 80) (90, 40) (60, 10) R (10, 20) circumference 271.112 NI Polygon Area 5200 Triangle 1: Area 550 Triangle 2: Area 1650 Triangle 3: Area 1800 Triangle 4: Area 1200 8/22/2018-gpe Page 1/4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
