Challenge 19

Description

The purpose of this challenge is load a struct array from a file. This challenge loads a file of airport codes and allows the user to query its contents.

 Requirements

  1. Using vi, create a text file that will contain the following data as shown below. Ask yourself, Why do the cities with multiple words use a dash instead of an actual space? (Los-Angeles instead of Los Angeles)
    BFL Bakersfield 3
    LAX Los-Angeles 35
    DFW Dallas 21
    IAH Houston 23
    ONT Ontario 14
    LGA La-Guardia 37
    AGU Aguascalientes 12
    HNL Honolulu 16
    JFK New-York 36
    
  2. Create a struct that will hold airport data
    struct Airport {
      string code;
      string city;
      int terminals;
    };
    
  3. Using a function int load_airports(Airport []). This function will return the number of airport records (lines of text) actually read from the file.
  4. Ask the user to enter an airport code. If the user enters the word “STOP” then stop asking for codes and exit the program.
  5. Using the airport code entered by the user, search the array for a matching airport record and report on its number of terminals (See sample interaction). If the airport code is not found, display an appropriate message.

Sample main()

int main()
{
  Airport airports[10];
  int count;
  string code;

  count = load_airports(airports);

  // ask the user to enter a code repeatedly until the user
  // enters STOP as the airport code

  return 0;
}

Sample Interaction

Enter an airport code: BFL
BFL (Bakersfield) has 3 terminals

Enter an airport code: HNL
HNL (Honolulu) has 16 terminals

Enter an airport code: YUV
No matching record found for YUV

Enter an airport code: IAH
IAH (Houston) has 23 terminals

Enter an airport code: STOP

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0019

Print Requirements