代写地址查询器,查询城市的经纬度。
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).
- Your program MUST use the following structure:
typedef struct place_s {
char name[100];
char country[30];
double latitude;
double longitude;
} place;
—|— - Your program MUST use the following two user-defined functions (the first
two must be developed, the last one is given):
place readPlace(FILE *inp); // read one place from a file pointed by inp
void printPlace(place *m); // print all attributes of a place pointed by m
double dist(double lat1, double long1, double lat2, double long2) {
double R = 6371;
double PI = 3.1415926536;
double dx, dy, dz;
double dist_mile;
long1 = long1 - long2;
long1 = long1 * (PI / 180);
lat1 = lat1 * (PI / 180);
lat2 = lat2 * (PI / 180);
dz = sin(lat1) - sin(lat2);
dx = (cos(long1) * cos(lat1)) - cos(lat2);
dy = sin(long1) * cos(lat1);
dist_mile = (asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R) / 1.609344;
return dist_mile;
}
—|—
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 USA
Tucson 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.2
Enter longitude: -110.9
The database entry closest to (33.2 -110.9) is
University of Arizona, USA
(Latitude, Longitude) = (32.231885, -110.950109)
with a distance of 3.665 miles
Continue? (q to quit): y
You can search for the database entry closest to a longitude and latitude:
Enter latitude: -35
Enter longitude: 150
The database entry closest to (35 150) is
Sydney Opera House, Australia
(Latitude, Longitude) = (-33.856784, 151.215297)
with a distance of 105.051 miles
Continue? (q to quit): q