The purpose of this demonstration is to show how a set of arrays of the same size can be used as a kind of "poor bloke's database" to store the identities of some objects, and also some information about the objects. In the example, the objects are persons, which are identified by their names, and the information about each object is a telephone number. The names are stored in the Names array and the phone numbers are stored in the Numbers array. The name in element j of the Names array corresponds to the number in element j of the Numbers array.
In this type of situation (and in real database systems), there is a "key" that is used as the identifier. In our case, the key is Names.
If we wanted to store and retrieve additional information, such as building, floor, or supervisor, we could just add more arrays.
The program consists of two modules: a data acquisition module and a search module. Since there are only two modules, and since first one and then the other is executed, there is no real need for a separate main module.
In the data acquisition module, after the user has entered a name, the name is placed in the Names array and a telephone number is requested and stored in the corresponding location of the Numbers array.
In the search module, a counter-controlled loop is used to search the Names array for the name the user entered. Once the name is found, the counter variable j is used to get the telephone number.
In the real world, the data collected would be stored in a file or database for later retrieval. We have not studied any methods for doing that. So I have surrounded the search logic with a "while" loop that repeats the search indefinitely. So to do more queries, you don't have to re-enter all the data!
Discussion Questions:
1. arraySize is declared as a constant value, and used in several places in the program. What is the advantage of doing this?
2. The search module is extremely inefficient. What is so inefficient about it? How could its efficiency be improved?
3. The search module is also rather less user-friendly than it should be. How could it be improved? How would you implement the improvement?