Homework 6 Time it took Matthew to Complete: 20 mins
• All programs must compile without warnings when using the -Wall and -Werror options
• Submit only the files requested
◦ Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc
• Your program must match the output exactly to receive credit.
◦ Make sure that all prompts and output match mine exactly.
◦ Easiest way to do this is to copy and paste them
• All input will be valid unless stated otherwise
• Print all real numbers to two decimal places unless otherwise stated
• The examples provided in the prompts do not represent all possible input you can receive.
• All inputs in the examples in the prompt are underlined
◦ You don’t have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
• If you have questions please post them on Piazza
Files to submit: perimeter.c
1. Write a program called perimeter.c that calculates the perimeter of a polygon.
1. The points of the polygon will be stored in a file and this file will be passed on
the command line arguments
2. The file itself will be a binary file containing integers
1. The first integer in the file is the number of points contained in the file
2. The remaining integers are the points, with the first integer being the x
coordinate and the second integer being the y coordinate.
3. There is an edge between each adjacent point and between the first point
and the last point
4. Each file contains at least 3 points
3. The perimeter of a polygon is the sum of the lengths of all of its edges
4. Use a double to store your perimeter and report the perimeter to the nearest 2
decimal points.
5. As an aside the example tests do not form actual polygons but assume that they
do.
Example. Assume that there is a file called example.txt. It will store the following information but in binary form. This example is just to give you a visualization of the data.
3
287 422
283 -981
781 647
./perimeter example.txt
The perimeter is 3648.30