Challenge 27

Description

The purpose of this challenge is load a tokenized 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, airports.txt, that will contain the following data as shown below. You don’t have to write code to create this file. 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
    GRV Grozny 8
    IAH Houston 23
    MGA Managua 11
    LGA La-Guardia 37
    AGU Aguascalientes 12
    BER Berlin 16
    JFK New-York 36
    
  2. In main, declare an array of strings, cities[20]
  3. Using a function int read_airports(string cities[], int threshold). This function will read the airports.txt file. As you read the entire file, identify which airports have at least threshold terminals and store the corresponding city names into the cities array. This function will also return the number of cities found whose number of terminals is at least threshold. Do not cout in this function. Use the cities array to hold the qualifying city names. Use main() to display the contents of the cities array. Ask yourself, why does this function return the number of qualifying cities? 
  4. Ask the user to enter an integer which represents the threshold number
  5. Display the cities found. Make sure you display the qualifying cities from main(). Consider the possibility that the cities array may not be completely filled with names – only display the names filled in by the read_airports function. 

Sample main()

int main()
{
  string cities[20];
  int count, threshold;

  // ask the user to enter a threshold number

  count = read_airports(cities, threshold);

  // show the cities that have at least threshold number of terminals

  return 0;
}

Sample Interaction

Enter a threshold number: 20
The following airports have at least 20 terminals:
Los-Angeles
Houston
La-Guardia
New-York

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0027

Print Requirements