Question
1.9 Lab: Airports 1 Programming language: C++ Data about airports are stored in three parallel arrays: one array contains airport codes (in ascending order), such
1.9 Lab: Airports 1
Programming language: C++
Data about airports are stored in three parallel arrays: one array contains airport codes (in ascending order), such as LAX, another array contains the names of the cities served, such as Los Angeles, and the third array contains the number of enplanements (commercial passenger boardings).
BUR 2077892 Burbank FAT 761298 Fresno LAX 39636042 Los Angeles OAK 5934639 Oakland RDD 43414 Redding SJC 5321603 San Jose SNA 5217242 Santa Ana
Change the binary search function to search airports based on their code, then display related data as shown below:
BUR found! See related data below: Code: BUR City: Burbank Enplanements: 2077892
or
STS not found!
HINT: Parallel arrays
These is the code to improve
// Lab: Airports 1 #include
using namespace std;
/* Write your code here */
int main(){ //constants definitions const int AIRPORTS = 50; // maximum size of arrays // arrays definitions string city[AIRPORTS] = {"Burbank", "Fresno", "Los Angeles", "Oakland", "Redding", "San Jose", "Santa Ana"}; string code[AIRPORTS] = {"BUR", "FAT", "LAX", "OAK", "RDD", "SJC", "SNA"}; int numOfEnpl[AIRPORTS] = {100433, 761298, 39636042, 5934639, 43414, 5321603, 5217242}; // other variables int size = 7; // actual size of arrays string target; cin >> target; // the airport code to search for /* Write your code here */ return 0; }
/* ******************************************* Definition of binary search This function performs the binary search on a string array. The array has the size of elements. A value stored in this array will be searched. It will return the array subscript if found. Otherwise, -1 will be returned. */
/* Write your code here */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started