Program to Calculate the Distance Between Cities on A Map Project
Write a program to allow the user to calculate the distance between cities on a map.
Sounds pretty complicated, eh? Don’t worry, we’ll make a few simplifications here:
- The distances are calculated in map units on the 2D map.
- Each city is given a set of coordinates relative to some point on the map. We’ll call this origin (0,0).
- There can only be a finite number of cities in the system at a given time (you decide this maximum).
But in order to make the system useful, we’ll have to add a few other features:
- Each city has a name in addition to its coordinates (you can assume a maximum length for these names; but they must be able to hold spaces: Los Angeles, New York, etc.).
- The user selects what action to take from a menu:
1) Enter city Information 2) calculate Distance between two cities 3) Print All cities 4) Quit
Make sure you allow them to choose their options by both the number and the capitalized letter(s) of the choice.
- They cannot calculate a distance until at least two cities have been entered.
- When they have exactly two cities, assume they are the ends and print their distance.
- When they have more than two cities, show them the list of cities and have them pick the two cities to calculate the distance between. Don’t let them choose the same city for both ends of the ‘trip’.
- If your list is full and they choose to enter another city, have them choose to either NOT enter the new city or to overwrite one of the earlier cities (they choose which one). Print the list of cities for them to choose from. (Remember, you still can’t exceed your maximum list size!)