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
- 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 RKV Reykjavic 1 BOG Bogota 2
- In main, declare an array of strings, cities[20]
- Using a function int read_airports(string cities[], int minimum). This function will read the airports.txt file. As you read the entire file, identify which airports have at least minimum 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 minimum. 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?
- Ask the user to enter an integer which represents the minimum number
- 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, minimum; // ask the user to enter a minimum number count = read_airports(cities, minimum); // show the cities that have at least minimum number of terminals return 0; }
Sample Interaction
Enter a minimum 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