City information exercises

xiaoxiao2021-03-06  22

Store information of several cities into a single-link list with headed nodes, urban information in the node includes city name, city's location coordinates. Requirements: (1) given a city name, return its position coordinates; (2) given a location coordinate P and a distance D, returning all the cities that are less than equal to D or equal.

#include #include #include #define maxSize 20typedef struct city {char name [maxSize]; float x; float y; structure,; int menu () {INT Choice; Printf ("************************** / n"); Printf ("* Exercise 2.1 * / n"); Printf ("************************* / n"); Printf ("1. New / N"); Printf ("2. According to City Find / N "); Printf (" 3. Find / N "from the center coordinate distance / N"); Printf ("4. Exit / N"); Printf ("============= ================ / n "); Printf (" Please select: "); scanf ("% d ", & choice); return choice;} float distance (float x, float) Y, float x0, float y0) {float disheat fourth (x0) * (x0) (Y-Y0) * (Y-Y0); Return Dis; City * Creat () {City * L, * r, * s; r = l = (city *) malloc (setof (city)); while (strcmp (r-> name, ".")! = 0) {s = (city *) malloc SIZEOF (")); if (s == null) {PUTS (" Error: Insufficient! "); Break;} else {printf (" City Name (Input "." end): "); scanf ("% S ", S-> Name); Printf (" Coordinate x, Y: "); scanf ("% f,% f ", & s-> x, & s-> y); r-> next = S; r = s;}} r-> next = null; return L;} city * locate (city * l, char * name) {city * p = l; while ((p! = null ) && (P-> Name, Name)! = 0)) P = P-> Next; Return P;} getCity (city * l, float x, float y, float d) {city * p = L- > Next; While (p! = null) {IF (Distance (P-> X, P-> Y, X, Y) Name, P-> x, p-> y); p = p-> next;}} main () {int CH = 0, i, c; float D, X, Y;

转载请注明原文地址:https://www.9cbs.com/read-44387.html

New Post(0)