Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- TASK 1: Revise airport-program.c and airport-program.h
- 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.
- 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.
- TASK 2: Write airport.c and airport.h
- 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.
- Airport struct
- 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.
- Airport functions
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Haversine formula
- 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.
- 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.
- 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.
- CODE Name Latitude Longitude
- SAT San Antonio Intl 29.533958 -98.469056
- BKK Bangkok Suvarnabhumi 13.681108 100.747283
- CDG Paris Charles De Gaulle 49.009722 2.547780
- GIG Rio De Janeiro Galeão -22.809999 -43.250555
- HKG Hong Kong Intl 22.308889 113.914722
- JFK New York-JFK 40.639926 -73.778694
- JNB O.R. Tambo Johannesburg -26.133693 28.242317
- LAX Los Angeles Intl 33.942496 -118.408048
- LHR London Heathrow 51.477500 -0.461388
- MEX Mexico City Benito Juarez 19.436303 -99.072096
- SIN Singapore Changi 1.359211 103.989333
- NRT Tokyo Narita 35.765556 140.385556
- Compilation
- To compile your code, you will need to include airport.c into the gcc call:
- kgcc airport.c airport-program.c -o nameOfExecutable -lm
- Submission
- 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
- This tarball will contain four files: airport-program.c, airport-program.h, airport.c, and airport.h
- #########################################
- Airport Program Menu
- #########################################
- 1 - Get Airport Information
- 2 - Get Airport Listing
- 3 - Get Distance Between Two Airports
- 4 - Find Airports Within Range
- 0 - Quit
- Enter your selection: 1
- Enter airport code: SAT
- SAT San Antonio Intl 29.533958 -98.469056
- #########################################
- Airport Program Menu
- #########################################
- 1 - Get Airport Information
- 2 - Get Airport Listing
- 3 - Get Distance Between Two Airports
- 4 - Find Airports Within Range
- 0 - Quit
- Enter your selection: 2
- SAT San Antonio Intl 29.533958 -98.469056
- LAX Los Angeles Intl 33.942496 -118.408048
- JFK New York-JFK 40.639926 -73.778694
- NRT Tokyo Narita 35.765556 140.385556
- LHR London Heathrow 51.477500 -0.461388
- MEX Mexico City Benito Juarez 19.436303 -99.072096
- #########################################
- Airport Program Menu
- #########################################
- 1 - Get Airport Information
- 2 - Get Airport Listing
- 3 - Get Distance Between Two Airports
- 4 - Find Airports Within Range
- 0 - Quit
- Enter your selection: 3
- Enter airport 1 code: LAX
- Enter airport 2 code: NRT
- The distance between Los Angeles Intl and Tokyo Narita is 5439.70 miles.
- #########################################
- Airport Program Menu
- #########################################
- 1 - Get Airport Information
- 2 - Get Airport Listing
- 3 - Get Distance Between Two Airports
- 4 - Find Airports Within Range
- 0 - Quit
- Enter your selection: LAX
- Enter airport code: Enter range in miles: 4500
- SAT San Antonio Intl 29.533958 -98.469056
- JFK New York-JFK 40.639926 -73.778694
- MEX Mexico City Benito Juarez 19.436303 -99.072096
- #########################################
- Airport Program Menu
- #########################################
- 1 - Get Airport Information
- 2 - Get Airport Listing
- 3 - Get Distance Between Two Airports
- 4 - Find Airports Within Range
- 0 - Quit
- Enter your selection: 0
- Good-bye!
- ****************************
- /*
- airport-program.c
- Project 1
- Firstname Lastname
- This is the driver for the airport program. It is displays the main menu presenting a selection of options
- for the user to get information about the airports in the system. The main function will then call functions
- in airport.c to calculate and retrieve information, which will then be printed here.
- */
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include "airport-program.h"
- /*
- printMenu
- ---------------------------
- This function prints the main menu.
- Returns: Nothing
- */
- void printMenu()
- {
- printf( "\n#########################################\n" );
- printf( "\tAirport Program Menu\n" );
- printf( "#########################################\n" );
- printf( "\t1 - Get Airport Information\n" );
- printf( "\t2 - Get Airport Listing\n" );
- printf( "\t3 - Get Distance Between Two Airports\n" );
- printf( "\t4 - Find Airports Within Range\n" );
- printf( "\t0 - Quit\n" );
- printf( "Enter your selection: " );
- }
- /*
- main
- ---------------------------
- This is the main driver of your program. See the comments below on how to complete the driver.
- Returns: 0
- */
- int main( int argc, char *argv[] )
- {
- Airport airports[ AIRPORTS ];
- fillAirports( airports );
- while( TRUE )
- {
- /* call the function to print the menu */
- printMenu();
- /* ask the user to input their selection */
- scanf( "%d", &choice );
- switch( choice )
- {
- case 1:
- /*
- 1. Ask the user to enter a 3-letter airport code.
- 2. Call findAirport()
- 3. If either airport's latitude or longitude of -99999, that means the airport was not found. In that case, print out an error.
- 4. Print the airport information
- */
- break;
- case 2:
- /*
- Call the printAirports() function
- */
- break;
- case 3:
- /*
- 1. Ask the user to enter a 3-letter airport code.
- 2. Ask the user to enter another 3-letter airport code.
- 3. Call findAirport() twice (for each of the airports entered)
- 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.
- 5. Print out the distance.
- */
- break;
- case 4:
- /*
- 1. Ask the user to enter a 3-letter airport code,
- 2. Ask the user to enter a range in miles (integer)
- 3. Call findAirport() to find the struct for that Airport
- 4. Call findInRange() to get an array of Airports within the range
- 5. Print the return array of Airport, if the array's length is empty state that no airports were found
- */
- break;
- case 0:
- printf( "Good-bye!\n" );
- return 0;
- }
- }
- return 0;
- }
- *********************************
- /*
- airport-program.h
- Project 1
- Firstname Lastname
- This file is the header file for the function and constant values used in the main driver (airport-program.c)
- */
- /* MAX is the maximum number of airports in the system */
- #define MAX 50
- /* boolean values */
- #define TRUE 1
- #define FALSE 0
- /*
- printMenu
- ---------------------------
- This function prints the main menu.
- Returns: Nothing
- */
- void printMenu();
- *********************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement