< previous page page_612 next page >

Page 612
would set aside 250 locations for the grades. However, some students will surely be absent on the day of the test. So the number of test grades is counted, and that number, rather than 250, is used to control the processing of the array.
We often call the actual number of values in an array the length of the array. If the length of an array is less than its declared size, functions that use array parameters should also have the length passed as a parameter. For example,
void Print( /* in */ const char grade[],      // Array for up to
                                              //   250 students
            /* in */       int  length   )    // Number of grades
                                              //   actually in array
The first two case studies at the end of this chapter-Comparison of Two Lists and Frequency of Certain Characters-demonstrate the technique of subarray processing.
Parallel Arrays
In many problems, there are several pieces of information that go together. For example, we might have ID numbers and grades for a particular group of students. We can set up an int (or long) array for the ID numbers and a char array for the grades. We can then access the components in the arrays in parallel. A particular ID number goes with a particular grade because they have the same position in their respective arrays; that is, they have the same index value. In Figure 11-9, the grade in grade [0] is the grade for the student whose ID number is in idNum[0]; the grade in grade[1] is the grade for the student whose ID number is in idNum[1]; and so on.
Another example of parallel arrays is the second case study in this chapter (Frequency of Certain Characters).
0612-01.gif
Figure 11-9
Parallel Arrays

 
< previous page page_612 next page >