Exercise: Global Distances
Write a program to read in the data from the supplied file and then display a table of the minimum distances between each pair of cities in kilometres. The distance should be that measured along the surface of the earth. Assume that the earth is a sphere of radius 6000km.
Each line in the data file cities.dat is 35 characters long and consists of the name and global co-ordinates of a city. The format of each line is:
| Field | Start | End | Width | Type |
|---|---|---|---|---|
| City Name | 1 | 12 | 12 | String |
| Latitude degrees | 14 | 15 | 2 | Unsigned Integer |
| Latitude minutes | 17 | 18 | 2 | Unsigned Integer |
| Latitude seconds | 20 | 21 | 2 | Unsigned Integer |
| Latitude direction | 23 | 23 | 1 | Character - 'N' or 'S' |
| Longitude degrees | 25 | 27 | 3 | Unsigned Integer |
| Longitude minutes | 29 | 30 | 2 | Unsigned Integer |
| Longitude seconds | 32 | 33 | 2 | Unsigned Integer |
| Longitude direction | 35 | 35 | 1 | Character - 'E' or 'W' |
Hint
The angle, α, between two points on the surface of a sphere is given by
where the points have the polar angles
and
respectively -
being latitiude and
being longitude.