|
|
|
|
|
|
|
A list of those students taking the exam |
|
|
|
|
|
|
|
|
A list of those students who are absent |
|
|
|
|
|
|
|
|
Discussion: How would you take attendance by hand? You would stand at the door with a class roster. As each student came in, you would check off his or her name. When all the students had entered, you would go through the roster, making a list of those present. Then you would do the same for those who are absent. |
|
|
|
|
|
|
|
|
This by-hand algorithm can serve as a model for your program. As each student enters the room, you enter his or her name at the keyboard. Your program scans the list of students for that name and marks that the student is present. When the last student has entered, you can enter a special sentinel name, perhaps ''EndData", to signal the program to print the lists. |
|
|
|
|
|
|
|
|
You can simulate "Mark that the student is present" by having a parallel array made up of Boolean values. This array is initialized to all FALSE; when a name is found in the list of students, the corresponding position in the second array is set to TRUE. |
|
|
|
|
|
|
|
|
You will have to prepare the list of students in advance from the class roster, which is ordered by social security number. If you enter the names directly from the roster, they will not be in alphabetical order. Does that matter? Yes, in this case it does matter. The size of the class is 200, and the students need to enter the exam room with minimum delay (because most arrive just before the exam starts). |
|
|
|
|
|
|
|
|
The size of the list and the speed required suggest that a binary search is appropriate. A binary search requires that the list be in sorted form. The names in the input file are in order by social security number, so your program must sort them alphabetically. All the names can be input at once and sorted using function SelSort, or each name can be put into its proper place as it is read using function Insert. You decide to take the second approach. |
|
|
|
|
|
|
|
|
A one-dimensional array of strings representing student names (student) |
|
|
|
|
|
|
|
|
A one-dimensional array of "checks" (isPresent) |
|
|
|
|
|
|
|
|
A temporary string to read a name into (stuName) |
|
|
|
|
|
|
|
|
Figure 12-9 pictures the data structures used in this program. |
|
|
|
|
|