Problem: Darth Vader wants to check that his TIE fighter pilots are patrolling adequately-sized regions of
the galaxy. He has files of data that contain the patrol coordinates for each of his pilots. With the fear
of being force choked, you have agreed to write a program that analyzes the data and determines the
size of the area patrolled by the pilots.
Given a list of checkpoint coordinates logged by the pilot that represent a polygonal shape, the area of
the shape can be calculated with the following formula
𝑛−2
1/2|∑(𝑥𝑖+1 + 𝑥𝑖)(𝑦𝑖+1 − 𝑦𝑖)
𝑖=0
http://gyazo.com/1394091de164ccf1bd9419951ea2519d (for the formula)
|
Input: All input will come from a file named pilot_routes.txt. The file will contain the pilot’s first name
followed by a list of coordinates separated by spaces. Each line in the file will represent a different pilot.
The format for each line will be the pilot’s first name followed by a list of x and y coordinates. There will
be a space between each pair of coordinates and a comma between the x and y coordinates. The first
and last set of coordinates will always be the same. See the sample below.
Output: All output will be written to a file named pilot_areas.txt. Once the calculation is performed, the
pilot’s name will be written to the file followed by a tab and the area of the polygonal shape
represented by the coordinates. The area should be rounded to 2 decimal places. Each pilot’s data will
be written on a separate line.
Limitations
There is no limit to the number of pilots listed in the file.
No pilot will have more than 15 coordinates associated with his/her patrol.
Arrays must be used to hold the pilot’s coordinates
Modular programming is required
Samples:
Input Line: Han 4,0 4,7.5 7,7.5 7,3 9,0 7,0 4,0
Output Line: Han 25.50