< previous page page_680 next page >

Page 680
We use an array of strings containing the months of the year. A month is read into a string variable. The Search function is used to search the array for the input string. If it is found at location index, we use index to access a parallel array containing the values of the enumeration type Months. In other words, we convert a month in string form to the equivalent month in the enumeration type by using parallel arrays, one containing strings and the other containing the enumeration equivalents. If the string is not found, the program can issue an error message and prompt the user to reenter the month.
Data Structures:
An array of strings containing the months of the year.
An array containing enumeration type values for the months of the year.
The two arrays look like those in Figure 12-8. Although these two arrays look similar, they have quite different representations in the computer. One contains the months in character form; the other contains the months in the form of an enumeration type.
Let's call the string representation of a month strMonth and the enumeration version month, as it is called in the BirthdayReminder program. The array of strings can be called strMonthAry, and the parallel array can be called monthAry. The algorithm for GetMonth using this structure is as follows:
0680-01.gif
Figure 12-8
Data Structures for
GetMonth Function

 
< previous page page_680 next page >