A polygon is defined by a list of vertices. The edges of the polygon are line...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <iostream> #include <fstream> #include <cmath> 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<<(ostream&,Point); // Formatted output of (x,y) coords istream& 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 = "<<p.perim() << endl; cout << "Centroid is "<<p.centroid() << endl; return 0: } // Write ALL the functions prototyped above main in the space below 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 <iostream> #include <fstream> #include <cmath> 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<<(ostream&,Point); // Formatted output of (x,y) coords istream& 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 = "<<p.perim() << endl; cout << "Centroid is "<<p.centroid() << endl; return 0: } // Write ALL the functions prototyped above main in the space below
Expert Answer:
Answer rating: 100% (QA)
include iostream include fstream include cmath using namespace std struct Point float x x coordinate ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Write a program that computes the spherical distance between two points on the surface of the Earth, given their latitudes and longitudes. This is a useful operation because it tells you how far...
-
Show that the shortest distance between two points in (three-dimensional) space is a straight line.
-
Determine (a) - Vertical distance between two points (b) - Height of an inaccessible object (c) - Horizontal distance With the help of Sextant
-
1. Was 1MDB a fraudulent venture from the beginning? Why or why not? 2. How did the US Government become involved in the 1MDB saga? 3. What does the involvement of so many financial institutions in...
-
Select the best answer. 1. The traditional business model of accounting is inadequate for governments and not-for-prot organizations primarily because businesses differ from governments and...
-
Find Vfb and Vec in the circuit infigure. + 1V - 3V 12V 3V - 1v+ e 2 V I> 2.
-
Water flows in a horizontal, rectangular channel with an initial depth of \(1 \mathrm{~m}\) and an initial velocity of \(4 \mathrm{~m} / \mathrm{s}\). Determine the depth downstream if losses are...
-
Refer to the data in E24-17. Requirements 1. Calculate each divisions RI. Interpret your results. 2. Calculate each divisions EVA. Interpret your results.
-
The Village of Seaside Pines prepared the following enterprise fund Trial Balance as of December 31, 2024, the last day of its fiscal year. The enterprise fund was established this year through a...
-
1. Using the spreadsheet model from Case 2.1 as a starting point, use Solver to find the optimal set of projects to approve. The solution should maximize the total NPV from the approved projects, and...
-
Provide a summary of each video. Include the 5 W's (who, what, when, where, why) and a summary of each department and/or topic mentioned in the videos. The reader should have a clear understanding of...
-
A taxpayer sells a patent that they have to a business interest and receives $2,500,000 on this sale. How is this income treated following the TCJA changes to IRC Section 1221(a)(3)?
-
The following are summaries of the cash book and bank accounts of J. Duncan who does not keep his books using the double entry system. Bank Summary Balance on 1 January 2018 Receipts Accounts...
-
Miguel plans to attend college and he starts saving 200 per month to pay for it. He will need 18,000 to pay the first-year cost. His aunt gave him a special gift of 2000 to use toward the cost. How...
-
Molson Coors Beverage Company issued a coupon bond 3.00 years ago. Southern Company issued a coupon bond 4.50 years ago. Both bonds pay coupons annually and mature in 9 years. The Molson Coors...
-
Addison works for a company and pays for half of her premiums on the insurance that covers employees who need to have sick pay. This comes from after-tax dollars. She ends up getting sick for a month...
-
Mustafa Ghadban, the manager of a downtown hotel, has noticed that the two Jamaican housekeepers regularly tease the Mexican housekeeper. The latter seems to take the ribbing in her stridemuch of it...
-
A. Select a recent issue (paper or online) of Report on Business Magazine, Canadian Business Magazine (online only), Bloomberg Businessweek, Fast Company, The Economist, or another business magazine....
-
The quick sort algorithm presented in the book selects the first element in the list as the pivot. Revise it by selecting the median among the first, middle, and last elements in the list.
-
Write a program that animates the AVL tree insert, delete, and search methods, as shown in Figure 26.1. 2 i = hash(key) An entry ikey value N-1 Hash function FIGURE 27.1 A hash function maps a key to...
-
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 1 public class Course { private String courseName; private String[] students = new...
-
How are the identifiable assets and liabilities acquired in a business combination measured?
-
What is meant by deferred consideration and how is it accounted for?
-
Distinguish between a business combination and a non-business acquisition.
Study smarter with the SolutionInn App