If you remember Pythagoras' theorem (the one about squares on hypotenuses), it is very easy to calculate the distance between two points. If you know how to calculate the distance between two points, it is very easy to find the perimeter of a two dimensional shape with straight edges. That is what your program must do.
Your program will read a description of just such a shape,
and calculate its perimeter. The description of the shape
will consist of the number of sides it has, followed by
the coordinates (x,y) of each of its corners. The corners
will always be listed in a sensible order, so that moving
from corner to corner in the order they are provided would
have the effect of walking round the outside of the shape.
![]() |
| |
The input will consist of a single number, N, giving the number of sides in the shape. Then there will be exactly N pairs of integers, being the (x,y) coordinates of the shape's corners.
The output should be a single line saying "Perimeter = X", where X is rounded to 2 digits after the decimal point. Note that there are single spaces around the = sign, and Perimeter is spelled with a capital P.
4 1 2 1 7 5 7 5 2
3 1 3 6 9 4 1
If you choose to use the C++ standard output object cout, you will have to take great care to get the output exactly right. Remember that exactly two digits are required after the decimal point.
It is recommended that you should use the stdio.h library for this problem. It will be quite difficult to correctly control the output format using vital. You can find details of the stdio functions here. Look especially at the sections on printf and scanf.