Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TASK 1: Revise the given files - 'airport-program.c' and 'airport-program.h (Bottom of question )' The driver of the program is airport-program.c, which has the main()?

TASK 1: Revise the given files - 'airport-program.c' and 'airport-program.h (Bottom of question )'

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.

The code written for you consists of a function 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 comments / instructions for what you need to do. It will usually involve asking the user for more input, calling some functions which you will create in airport.c (see next task), and print the output.?

TASK 2: Create and write airport.c and airport.h

Write the source (.c) and header (.h) files for an 'airport' system. If you see in the 'airport-program.c' there is an array of ? Airport? struct created. You need to create this struct , add the required ? # define and create functions relating to airports. The main()? function of the 'airport-program.h' will be calling the various Airport functions using this array of Airport?struct ?

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 decimal numbers (double) 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 this is to be defined by you using a #define preprocessor statement.

  1. 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.
  2. 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 (similar to the provided data at the end) since this function will be called by the printAirports() where all airport information is printed.?
  3. 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.?
  4. 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/Distance 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.
  5. 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.
  6. 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 the following 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

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* ?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 ?

#include

?#include /* ? ? 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[MAX]; // MAX to be defined in 'airport.h' ? ?

fillAirports(airports); ? ? while(1) ? ?{ ? ? ? ?

/* Call the function to print the menu */ ? ? ??

?printMenu(); ? ? ? ?

/* Get the menu choice from the user */ ? ? ? ?

scanf("%d", &choice); ? ? ? ?

switch(choice) ? ? ? ?{ ? ? ? ? ? ?

? ? ?case 1: ?/* 1. Get a 3-letter airport code from the user.

2. Call findAirport()?

3. If either the airport's latitude or longitude is -99999, that means the airport was not found. Print an appropriate error.

4. If airport found, print the airport information.*/

break;

? ? ? ? ? ? case 2: /* ? ? ? ? ? ? ? ? ? ?Call the printAirports() function.*/

break;

? ? ? ? ? ? case 3:/* 1. Get two 3-letter airport codes from the user.

2. Call findAirport() twice (one each for each of the airport codes entered).

3. If either airport's latitude or longitude is -99999, that means that airport was not found. Print an appropriate error.?

4. If both airports found successfully, call the calculateDistance() function.

5. Print out the distance between the two airports. */

break;

? ? ? ? ? ? case 4:/* 1. Get a 3-letter airport code from the user.?

?2. Call findAirport() on this origin airport code.?

3. If the airport's latitude or longitude is -99999, that means the airport was not found. Print an appropriate error.?

4. If airport found successfully, get a range in miles (integer) from the user.

5. Call findInRange() to get an array of Airports within the specified range of the origin airport.

6. Print the return array of airports in range. If the result length returned is zero, print a message that no airports were found.*/

?break;?

? ? ? ? ? ?case 0: ? ? ? ? ? ?

default: ? ? ? ? ? ? ? ?

printf("Good-bye!"); ? ? ? ? ? ? ? ?

return 0; ? ? ? ?

} ? ?

} ? ?

return 0;?

}

/* ? ?printMenu ? ?--------------------------- ? ?This function prints the main menu. ? ?Returns: Nothing */?

void printMenu() { ? ?

printf("#########################################"); ? ?

printf("\tAirport Program Menu"); ? ?

printf("#########################################"); ? ?

printf("\t1 - Get Airport Information"); ? ?

printf("\t2 - Get Airport Listing"); ? ?

printf("\t3 - Get Distance Between Two Airports"); ? ?

printf("\t4 - Find Airports Within Range"); ? ?

printf("\t0 - Quit"); ? ?printf("Enter your selection: ");?

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/* ? ?airport-program.h ? ?Project 1 ? ?Firstname Lastname ? ? This file is the header file for declaring the functions used in the 'airport-program.c' file. ? ?It is also used for including the 'airport.h' header file where the constants, airport structure and other functions are declared. */?

#include "airport.h" /* ? ? printMenu ? ?--------------------------- ? ?This function prints the main menu. ? ?Returns: Nothing */?

void printMenu();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Problem files are uploaded at httpsgithubcomravireddy07HelloExperttreemaster7307370075 All cases and iss ues are solved according to the description provided Program is working successfully with accur... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Operations Research

Authors: Frederick S. Hillier, Gerald J. Lieberman

10th edition

978-0072535105, 72535105, 978-1259162985

More Books

Students also viewed these Programming questions