Pointing the Way

 

Program POINT.C, POINT.CPP, POINT.PAS

A compass is usually thought of as having 4 primary points at North, East, South, and West. These directions correspond to points on a circle, with North at 0 degrees, East at 90 degrees, South at 180 degrees, and West at 270 degrees. There can be many points between the primary points. For example, the point North-East is halfway between North and East, at 45 degrees and East-North-East is halfway between East and North-East at 67.5 degrees.

This plan has been determined to be too restrictive for space travel, so you have been asked to create a more general compass, with anywhere from 3 to 26 primary points.

For example, if a compass were to have 5 points, for simplicity sake, name them with the first five letters of the alphabet as below:

The point A is oriented with 0 degrees. This means B is at 72 degrees, C is at 144 degrees, D is at 216 degrees, and E is at 288 degrees. At 36 degrees, halfway between A and B, is the compass point AB. At 18 degrees, halfway between A and AB is the compass point AAB. At 54 degrees, halfway between AB and B is the point BAB.

To name compass points, follow the example in the chart below for a compass with 4 points and the rules below:

-The major compass points are called 1-points. The name of a 1-point is a single alphabetic character, where the first 1-point is 'A' (at 0 degrees) and others are B, C, ... in clockwise order.
· 2-points are halfway between two one points. The name of the 2-point between two contiguous 1?points, P an Q (specified in clockwise order,) is PQ.

Your program must take a number of compass points and a group of compass points for each and return the degree measure of the compass point. For example, for the example above, a 5 pointed compass would place BAB at 54 degrees and CD at 180 degrees.