Problem #17

Code Wars II
Danger Level: Double Black uu





}Airport Geography~

Point Value: 15
 

Problem Statement

The FAA regulates and restricts air flight in certain regions, especially near airports.  Each airport has an air traffic control tower that controls the airspace within a designated region.  A pilot who enters a controlled airspace must usually communicate with the tower, possibly changing frequencies while flying through that airspace.  In this problem we'll write a program to determine which air spaces are entered by a specific flight plan.

Reality: In reality, air traffic control spaces have irregular 3D shapes.  Reality is also quite complex in that our planet is apparently spherical.  I haven't actually observed this myself, but it is a well accepted postulate.  It certainly makes the math for this problem quite a bit harder than I want it to be.

Simplicity: For simplicity, we'll model this complex reality by oversimplifying.  Radically oversimplifying.  First, we'll assume that we can map longitude and latitude to miles in a linear fashion.  This is patently untrue, and will make our results wholly inaccurate.  But this is only a contest.  To make our results a little more meaningful, we will restrict our map of sites to Texas, because Texas is fairly flat, heh, heh.  Based on our first assumption we'll also assume that flight paths are straight lines in a rectangular (longitude, latitude) coordinate system.  Next we'll define the controlled airspace as a vertical cylinder with the control tower at the center.  Finally, based on our first wildly inaccurate assumption, we'll convert degrees to miles using the following formulae:

MILES  =  50.23 * DEGREES LONGITUDE
MILES  =  60.07 * DEGREES LATITUDE

The program should read a data file describing all these controller air spaces.  The program will then read an aircraft departure and destination from a separate file.  Finally, the program will write the names of all of the air spaces through which the aircraft must fly in order of their occurrence.
 

Program Input

The file AIRSPACE.DAT contains six lines of text for each air traffic control tower.  Each airport data block contains the name of the airport, the tower's longitude and latitude in degrees, and the radius of that tower's controlled air space in miles.  All airports are located in Texas (mostly!).  The names and locations of the airports are accurate, but the tower control radius figures are fictional for this problem.  Here are some sample lines for a single airport:

Airport Name: GEORGE BUSH INTCNTL HOUSTON
IATA: IAH
Location: HOUSTON, TX, UNITED STATES
Latitude: 29º 58' N
Longitude: 95º 20' W
Radius: 25 MILES

After reading the airspace data file, the program should read a series of flight paths from the input file PROB17.IN.  Each line of the input file contains (1) the IATA codes for the departure and arrival locations, in that order, (2) the departure time in 24 hr format, and (3) the average aircraft speed in miles/hour.  For example:

SAT IAH 08:14 120MPH
DFW SAT 08:14 120MPH
ELP IAH 17:53 185MPH
 
 

Program Output

The program should write the results to the output file PROB17.OUT.  For each flight plan, the program should write the IATA codes for the departure and arrival airports on a single line.  Then it must print the names of the airports through whose airspace the aircraft will fly.  The airports should be listed in the order they will be crossed in flight.  The actual departure and arrival should be considered separate "intersections" as shown in the example output.  For each airport print (1) the airport name, (2) the name of the city where the airport is located, (3) the longitude and latitude of the intersection between the flight path and the airspace.  Note that some air spaces overlap the towers of other airports.  All airspace's which include the flight path must be reported.  For example, the output for the first input line above is:

From: SAT   To: IAH
DEPART: SAN ANTONIO INTL(SAT)
        SAN ANTONIO, TX, UNITED STATES
        29º 32' N by 98º 28' W
CROSS:  NEW BRAUNFELS MUNICIPAL(3R5)
        NEW BRAUNFELS, TX, UNITED STATES
        29º 34' N by 98º 9' W
CROSS:  GERONIMO FIELD(T90)
        SEGUIN, TX, UNITED STATES
        29º 35' N by 98º 4' W
CROSS:  SAN ANTONIO INTL(SAT)
        SAN ANTONIO, TX, UNITED STATES
        29º 35' N by 98º 4' W
CROSS:  GERONIMO FIELD(T90)
        SEGUIN, TX, UNITED STATES
        29º 36' N by 97º 53' W
CROSS:  NEW BRAUNFELS MUNICIPAL(3R5)
        NEW BRAUNFELS, TX, UNITED STATES
        29º 37' N by 97º 51' W
CROSS:  GEORGE BUSH INTCNTL HOUSTON(IAH)
        HOUSTON, TX, UNITED STATES
        29º 53' N by 95º 55' W
ARRIVE: GEORGE BUSH INTCNTL HOUSTON(IAH)
        HOUSTON, TX, UNITED STATES
        29º 58' N by 95º 20' W

2 POINT BONUS: In addition to the requirements above, the program should also display (1) the average speed on the first line, (2) the prompt ENTER or EXIT instead of CROSS, and (3) the estimated time at which the aircraft enters and exits each controlled airspace (assuming the aircraft maintains the average speed throughout the entire flight).  Times should be displayed in the same 24 hr format as the input.  The same example input flight plan would yield this result:

From: SAT   To: IAH   AvgSpeed:   120MPH
DEPART: SAN ANTONIO INTL(SAT)
        SAN ANTONIO, TX, UNITED STATES
        08:14   29º 32' N by 98º 28' W
ENTER:  NEW BRAUNFELS MUNICIPAL(3R5)
        NEW BRAUNFELS, TX, UNITED STATES
        08:21   29º 34' N by 98º 9' W
ENTER:  GERONIMO FIELD(T90)
        SEGUIN, TX, UNITED STATES
        08:23   29º 35' N by 98º 4' W
EXIT:   SAN ANTONIO INTL(SAT)
        SAN ANTONIO, TX, UNITED STATES
        08:23   29º 35' N by 98º 4' W
EXIT:   GERONIMO FIELD(T90)
        SEGUIN, TX, UNITED STATES
        08:28   29º 36' N by 97º 53' W
EXIT:   NEW BRAUNFELS MUNICIPAL(3R5)
        NEW BRAUNFELS, TX, UNITED STATES
        08:29   29º 37' N by 97º 51' W
ENTER:  GEORGE BUSH INTCNTL HOUSTON(IAH)
        HOUSTON, TX, UNITED STATES
        09:18   29º 53' N by 95º 55' W
ARRIVE: GEORGE BUSH INTCNTL HOUSTON(IAH)
        HOUSTON, TX, UNITED STATES
        09:33   29º 58' N by 95º 20' W