讲解:CS103 Place ListsR、R

代写地址查询器,查询城市的经纬度。NoteName your file labexam2.cWhen you finish, submit the .c file in the designated dropbox on D2L.The Dropbox will be closed at the end of your lab sessionIf 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 thata) 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 USAd) 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:123456typedef struct place_s char name[100]; char country[30]; double latitude; double longitude; place;& 2) Your program MUST use the following two user-defined functions (the first two must be developed, the last one is given):1234567891011121314151617place readPlace(FILE *inp); // read one place from a file pointed by inpvoid printPlace(place *m); // print all attributes of a place pointed by mdouble 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 转自:http://www.3daixie.com/contents/11/3444.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容