Question: A polygon is defined by a list of vertices. The edges of the polygon are line segments connecting successive vertices, with the final edge

A polygon is defined by a list of vertices. The edges of

A polygon is defined by a list of vertices. The edges of the polygon are line segments connecting successive vertices, with the final edge connecting the last vertex to the first. Data describing an arbitrary polygon is stored in a disk file called poly.dat. The first number in this file identifies the number of vertices, while each of the following lines give ther and y coordinates of one vertex. Using the structures and classes provided in the template code polygon.cpp, write the additional code required so that your program can reproduce the following result from the example poly.dat provided: Poly.dat: 3 00 20 02 Polygon has perimeter 6.82843 Centroid is (0.666667,0.666667) Polygon.cpp: #include #include #include using namespace std; struct Point Point structure ///////// {m float x; //x coordinate of Point float y; // y coordinate of Point float dist(Point Point); // Computes the distance between two Points. ostream& operator < >(istream&,Point&); // Load xy coords from source class Line Point start; // Start Point of Line Point end; // End Point of Line public: Line class //////////m Line(void); // Default constructor (c'tor) Line(Point a Point b); // Overloaded c'tor for specified start and end points float length(void); // Gives length of a Line (distance between start and end) class Polygon Point" v; Line* e: int nvert: public: Polygon(int); -Polygon(void): float perim(void): // Computes perimeter of polygon Point centroid(void); // Computes centroid of polygon friend istream& operator>>(istream&,Polygon&); // load data from a source int main(void) { Polygon class ///////////// // List of vertices //Each edge is Line connecting successive vertices // Number of vertices (-length of arrays v and e) // Constructor (c'tor) -- input is number of vertices // Destructor (d'tor) ifstream vfile("poly.dat"); int n; vfile >> n: Polygon p(n); vfile >> p: cout < < "Polygon has perimeter = "

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include iostream include fstream include cmath using namespace std struct Point float x x coordinate ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!