Note
Name your file labexam2.c
When you finish, submit the .c file in the designated dropbox on D2L.
The Dropbox will be closed at the end of your lab session
If you cannot submit your code in the designated Dropbox, talk to TA ASAP!
The file placelist.txt contains place information (name, country, latitude and longitude). Write a C program that
- a) Asks the user to enter the file that contains the place database.
- b) Reads places from the place database file and stores them in an array of type place. Assume that no more than 100 places are in the placelist.txt file.
- c) prints places that are located in the USA
- d) allows a user to find the closest place to a given latitude and longitude. Upon a query, it displays the set of places and also the distance.
- e) is interactive (q to quit).
1) Your program MUST use the following structure:
1 | typedef struct place_s { |
2) Your program MUST use the following two user-defined functions (the first two must be developed, the last one is given):
1 | place readPlace(FILE *inp); // read one place from a file pointed by inp |
Note: There is no need to use a linked list. The number of places in the given does not exceed 100 =>
an array of type place will work. You will not be penalized if you choose to use a linked list.
Make sure you understand the sample code execution thoroughly before writing the code.
Sample Code Execution:
Places in USATucson International Airport, USA(Latitude, Longitude) = (32.114510, -110.939227)University of Arizona, USA(Latitude, Longitude) = (32.231885, -110.950109)Statue of Liberty, USA(Latitude, Longitude) = (40.689249, -74.044500)Golden Gate Bridge, USA(Latitude, Longitude) = (37.819929, -122.478255)You can search for the database entry closest to a longitude and latitude:Enter latitude: 32.2Enter longitude: -110.9The database entry closest to (33.2 -110.9) isUniversity of Arizona, USA(Latitude, Longitude) = (32.231885, -110.950109)with a distance of 3.665 milesContinue? (q to quit): yYou can search for the database entry closest to a longitude and latitude:Enter latitude: -35Enter longitude: 150The database entry closest to (35 150) isSydney Opera House, Australia(Latitude, Longitude) = (-33.856784, 151.215297)with a distance of 105.051 milesContinue? (q to quit): q