Assignment 1: Distance Calculator

Objectives

Introduction

Geographic coordinates are given using longitude, which is a measure of how far east or west from a fixed line of longitude a place is, and latitude, which measures how far north or south of the equator a place is. Longitude and latitude are often expressed in degrees. Given such a representation one can compute the distance between two points ($lat1$, $lon1$) ($lat2$, $lon2$) by (Note that we are making the simplifying assumption that the Earth is a sphere.)

Assignment

Write a C++ program that reads from standard input the coordinates of two points on Earth and outputs the distance between them in miles. The input will be given on four lines: the latitude and longitude of one point on separate lines and in that order, then the latitude and longitude of a second point. Each line will be either decimal degrees, integer degrees and decimal minutes, or integer degrees and minutes and decimal seconds, where the decimal part of the input may (but not must) include a fractional part. The values given are within the range +/- 90 degrees for latitude and +/- 180 degrees for longitude and the minus sign, when present, is on the degrees component. For example, the following would be legal input:
51.4826
0
41 18.5
-72 55 40.44
(note that when the degrees are negative the negative distributes through the minutes and seconds, so the decimal equivalent of -72 55 40.44 is -72.9279). The output should be in the default format for a double.

If the input does not satisfy these requirements then your program must behave gracefully – it must not crash or go into an infinite loop.

Example

If the input file lon_nhv.txt contains
51.4826
0
41 18.5
-72 55 40.44
Then the execution of the program would be as follows.
$ ./Distance < lon_nhv.txt
3397.54  

Submissions

Submit whatever source code (.cpp and .hpp) files you created and a makefile that builds an executable called Distance when called with no arguments. Also submit your log file as described on the assignment index page.