Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this exercise, you will create two parallel arrays, add data to them while keeping them in parallel sync ( each name / Lnumber pair
For this exercise, you will create two parallel arrays, add data to them while keeping them in parallel sync each nameLnumber pair will have the same index always sort them, and finally search them with a binary search. This will be practice in storing data in sorted arrays, displaying and sorting parallel arrays, and finally doing searches.
Program Specification
For this exercise, you will create two parallel arrays. The first one will hold names and the second will hold Lnumbers. You will get a name and Lnumber pair and insert them in the two arrays, with the Lnumber array in sorted order from smallest to largest and indexes in the two arrays matching so that each name stays with the correct Lnumber. Then you will display them, sort them based on the name which will change the order of the Lnumbers so that each name stays with the appropriate Lnumber display them again, and finally do a binary search based on the name.
For this, as in all assignments, you are expected to follow the course programming style guidelines and to properly implement both header and source files for your functions. All input for this lab will be strings Lnumbers will be of the form L where the s are replaced by other digits
The minimum functions you are required to implement are:
getInteger
o pass in min and max value
o gets and validates an integer between min and max
o returns the value
fillArrays
o pass in the two arrays and how many items to get
o reads a name and an Lnumber
o using the Lnumber
finds the proper location to insert in the arrays
maintains Lnumber ordering from smallest to largest
inserts name in name array and Lnumber in its array, each at the proper location
o updates the arrays via reference
o no return values
sortArrays
o pass the arrays and count
o sorts the name array in ascending order with a selection sort
keeps the Lnumber array in matching order
o no return values
displayArrays
o pass the arrays safely and item count
o display the arrays in columns with names and matching Lnumbers
o no return values
binSearch
o pass an array safely, item count, and value to search for
o perform a binary search
o return true if the value is present, false otherwise
Main will define two string arrays of size find out how many nameLnumber pairs to input using getInteger between and fill the arrays, display them, sort them, display them again, and then search for five names and display the results, terminating when done.
Helper function
To make fillArrays simpler, you could add a method insertArrays that is called to actually add the data to the arrays.
insertArrays
o pass in key array, value array, count, key, and value
o using key and key array
move items in both arrays up as necessary
insert key in key array
insert value in value array
o this is similar to the insertArray method in sorted Arrays, but maintains a second array in parallel
o updates the arrays via reference
o no return values
Program Tips
Define your program with stub functions, then code and test functions in this order:
getInteger
fillArrays
displayArrays
sortArrays
binSearch
As a debugging idea, you should call display before and after the sort to verify that it is working properly.
If you are having issues with separate compilation, get your program working with stubs as a single file and then split it up into header and source. Once you get used to separate compilation, you can skip this initial step.
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