Advertisement
Guest User

project

a guest
Jun 25th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.73 KB | None | 0 0
  1. In this project, you will create a program that manages information about airports. The program will maintain a list of airports and their coordinates. It allows users to ask for information about an airport (based on its 3-letter code), find the distance between airports, and find airports that are within a given distance of a selected airport.
  2.  
  3. TASK 1: Revise airport-program.c and airport-program.h
  4.  
  5. The driver of the program is airport-program.c, which has the main() function. The source file and the header file are attached. You will need to add your own code.
  6.  
  7. Much of the code written for you is to print out a menu in which users can select one of five options. A switch statement has been set up to handle each of the inputs. Within each case, there are instructions for what you need to do, which usually involve asking the user for more input, calling some functions in airport.c (see next task), and print out the output.
  8.  
  9. TASK 2: Write airport.c and airport.h
  10.  
  11. Write the source (.c) and header (.h) files with the following #define's, struct's, and functions relating to airports. An array of Airport struct's is created in the main() function. This is a list of airports entered into the system. Information for six airports are given to you. The main() function will be calling the various Airport functions using this array of Airport struct's.
  12.  
  13. Airport struct
  14.  
  15. Create a struct named Airport. This struct will keep track of an airport's 3-letter code, its full name, its latitude, and its longitude. This 3-letter code is the IATA code for airports around the world. For example, San Antonio is SAT; Dallas-Fort Worth is DFW, George Bush Intercontinental-Houston is IAH, and Austin-Bergstrom is AUS. Latitudes and longitudes are floating point numbers and are represented in degrees.
  16.  
  17. Airport functions
  18.  
  19. Write the following functions that use the Airport struct. The function headers are given to you along with a brief description of what the function does. MAX is a constant value defined by a #define preprocessor statement.
  20.  
  21. void printAirports( Airport airports[ MAX ], int length ) - This function prints out all information for all Airports in the airports array. This function will use the printAirport() function.
  22. void printAirport( Airport airport ) - This function prints out the information for a single Airport struct. Format it in a way such that the code, name, latitude, and longitude are in columns since this function will be called by the printAirports() where all airport information is printed.
  23. Airport findAirport( Airport airports[ MAX ], int length, char code[ 4 ] ) - This function finds an Airport struct that matches the 3-letter airport code. If it doesn't find the airport, create a temporary struct to return with -99999 as its latitude and longitude.
  24. double calculateDistance( Airport airport1, Airport airport2 ) - This function calculates the distance between two airports based on its coordinates (latitude and longitude), and returns the distance. See the Haversine formula below. Assume that both Airport struct's have valid values.
  25. This is the pseudocode for Haversine formula (Source: http://andrew.hedges.name/experiments/haversine/). You first need to convert latitude and longitude to radians. The radius of the Earth is 3959 miles.
  26. Haversine formula
  27. You can check the distance between two airports on the Great Circle Mapper (http://www.gcmap.com). Enter the two airport codes separated by a dash (e.g., LAX-LHR) and click Map to find the distance. Note that there may be a +/- 50 mile difference in distances between your answer and the distance on the Great Circle Mapper.
  28. void findInRange( Airport airports[ MAX ], int length, Airport origin, int range, Airport output[ MAX ], int *resultsLength ) - This function will find all airports that are within range miles of the origin airport. This is done by calculating the distance between the origin airport and all other airports in the array. An empty array output will also be passed in where you will store the Airport info for each airport in range. You will also need to keep track of the number of airports within range and write that number through resultsLength.
  29. int fillAirports( Airport airports[ MAX ] ) - This function manually adds in airport information into the array. The function will return the number of airports added. You will add these 12 airports.
  30. CODE Name Latitude Longitude
  31.  
  32. SAT San Antonio Intl 29.533958 -98.469056
  33.  
  34. BKK Bangkok Suvarnabhumi 13.681108 100.747283
  35.  
  36. CDG Paris Charles De Gaulle 49.009722 2.547780
  37.  
  38. GIG Rio De Janeiro Galeão -22.809999 -43.250555
  39.  
  40. HKG Hong Kong Intl 22.308889 113.914722
  41.  
  42. JFK New York-JFK 40.639926 -73.778694
  43.  
  44. JNB O.R. Tambo Johannesburg -26.133693 28.242317
  45.  
  46. LAX Los Angeles Intl 33.942496 -118.408048
  47.  
  48. LHR London Heathrow 51.477500 -0.461388
  49.  
  50. MEX Mexico City Benito Juarez 19.436303 -99.072096
  51.  
  52. SIN Singapore Changi 1.359211 103.989333
  53.  
  54. NRT Tokyo Narita 35.765556 140.385556
  55.  
  56. Compilation
  57.  
  58. To compile your code, you will need to include airport.c into the gcc call:
  59.  
  60. kgcc airport.c airport-program.c -o nameOfExecutable -lm
  61.  
  62. Submission
  63.  
  64. Be sure that your code follows the class coding style requirements. Your output should be similar in format as compared to the sample output attached. Submit your program as a tarball labeled lastname-firstname-project1.tar.gz
  65.  
  66. This tarball will contain four files: airport-program.c, airport-program.h, airport.c, and airport.h
  67.  
  68. #########################################
  69. Airport Program Menu
  70. #########################################
  71. 1 - Get Airport Information
  72. 2 - Get Airport Listing
  73. 3 - Get Distance Between Two Airports
  74. 4 - Find Airports Within Range
  75. 0 - Quit
  76. Enter your selection: 1
  77.  
  78. Enter airport code: SAT
  79. SAT San Antonio Intl 29.533958 -98.469056
  80.  
  81.  
  82. #########################################
  83. Airport Program Menu
  84. #########################################
  85. 1 - Get Airport Information
  86. 2 - Get Airport Listing
  87. 3 - Get Distance Between Two Airports
  88. 4 - Find Airports Within Range
  89. 0 - Quit
  90. Enter your selection: 2
  91.  
  92. SAT San Antonio Intl 29.533958 -98.469056
  93. LAX Los Angeles Intl 33.942496 -118.408048
  94. JFK New York-JFK 40.639926 -73.778694
  95. NRT Tokyo Narita 35.765556 140.385556
  96. LHR London Heathrow 51.477500 -0.461388
  97. MEX Mexico City Benito Juarez 19.436303 -99.072096
  98.  
  99.  
  100. #########################################
  101. Airport Program Menu
  102. #########################################
  103. 1 - Get Airport Information
  104. 2 - Get Airport Listing
  105. 3 - Get Distance Between Two Airports
  106. 4 - Find Airports Within Range
  107. 0 - Quit
  108. Enter your selection: 3
  109.  
  110. Enter airport 1 code: LAX
  111. Enter airport 2 code: NRT
  112. The distance between Los Angeles Intl and Tokyo Narita is 5439.70 miles.
  113.  
  114.  
  115. #########################################
  116. Airport Program Menu
  117. #########################################
  118. 1 - Get Airport Information
  119. 2 - Get Airport Listing
  120. 3 - Get Distance Between Two Airports
  121. 4 - Find Airports Within Range
  122. 0 - Quit
  123. Enter your selection: LAX
  124.  
  125. Enter airport code: Enter range in miles: 4500
  126. SAT San Antonio Intl 29.533958 -98.469056
  127. JFK New York-JFK 40.639926 -73.778694
  128. MEX Mexico City Benito Juarez 19.436303 -99.072096
  129.  
  130.  
  131. #########################################
  132. Airport Program Menu
  133. #########################################
  134. 1 - Get Airport Information
  135. 2 - Get Airport Listing
  136. 3 - Get Distance Between Two Airports
  137. 4 - Find Airports Within Range
  138. 0 - Quit
  139. Enter your selection: 0
  140.  
  141. Good-bye!
  142. ****************************
  143.  
  144. /*
  145. airport-program.c
  146. Project 1
  147. Firstname Lastname
  148.  
  149. This is the driver for the airport program. It is displays the main menu presenting a selection of options
  150. for the user to get information about the airports in the system. The main function will then call functions
  151. in airport.c to calculate and retrieve information, which will then be printed here.
  152. */
  153. #include <stdio.h>
  154. #include <string.h>
  155. #include <math.h>
  156. #include "airport-program.h"
  157.  
  158. /*
  159. printMenu
  160. ---------------------------
  161. This function prints the main menu.
  162. Returns: Nothing
  163. */
  164. void printMenu()
  165. {
  166. printf( "\n#########################################\n" );
  167. printf( "\tAirport Program Menu\n" );
  168. printf( "#########################################\n" );
  169. printf( "\t1 - Get Airport Information\n" );
  170. printf( "\t2 - Get Airport Listing\n" );
  171. printf( "\t3 - Get Distance Between Two Airports\n" );
  172. printf( "\t4 - Find Airports Within Range\n" );
  173. printf( "\t0 - Quit\n" );
  174. printf( "Enter your selection: " );
  175. }
  176.  
  177. /*
  178. main
  179. ---------------------------
  180. This is the main driver of your program. See the comments below on how to complete the driver.
  181. Returns: 0
  182. */
  183. int main( int argc, char *argv[] )
  184. {
  185. Airport airports[ AIRPORTS ];
  186. fillAirports( airports );
  187.  
  188. while( TRUE )
  189. {
  190. /* call the function to print the menu */
  191. printMenu();
  192. /* ask the user to input their selection */
  193. scanf( "%d", &choice );
  194.  
  195. switch( choice )
  196. {
  197. case 1:
  198. /*
  199. 1. Ask the user to enter a 3-letter airport code.
  200. 2. Call findAirport()
  201. 3. If either airport's latitude or longitude of -99999, that means the airport was not found. In that case, print out an error.
  202. 4. Print the airport information
  203. */
  204. break;
  205. case 2:
  206. /*
  207. Call the printAirports() function
  208. */
  209. break;
  210. case 3:
  211. /*
  212. 1. Ask the user to enter a 3-letter airport code.
  213. 2. Ask the user to enter another 3-letter airport code.
  214. 3. Call findAirport() twice (for each of the airports entered)
  215. 4. If either airport's latitude or longitude of -99999, that means the airport was not found. In that case, print out an error. Otherwise, call the calculateDistance() function.
  216. 5. Print out the distance.
  217. */
  218. break;
  219. case 4:
  220. /*
  221. 1. Ask the user to enter a 3-letter airport code,
  222. 2. Ask the user to enter a range in miles (integer)
  223. 3. Call findAirport() to find the struct for that Airport
  224. 4. Call findInRange() to get an array of Airports within the range
  225. 5. Print the return array of Airport, if the array's length is empty state that no airports were found
  226. */
  227. break;
  228. case 0:
  229. printf( "Good-bye!\n" );
  230. return 0;
  231. }
  232. }
  233.  
  234. return 0;
  235. }
  236. *********************************
  237.  
  238. /*
  239. airport-program.h
  240. Project 1
  241. Firstname Lastname
  242.  
  243. This file is the header file for the function and constant values used in the main driver (airport-program.c)
  244. */
  245. /* MAX is the maximum number of airports in the system */
  246. #define MAX 50
  247.  
  248. /* boolean values */
  249. #define TRUE 1
  250. #define FALSE 0
  251.  
  252. /*
  253. printMenu
  254. ---------------------------
  255. This function prints the main menu.
  256. Returns: Nothing
  257. */
  258. void printMenu();
  259. *********************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement