|
|
|
|
|
|
|
Get Phone Number (parameters to be determined) |
|
|
|
|
|
|
|
|
Read areaCode
Read phoneNumber |
|
|
|
|
|
|
|
|
|
Get Birth Data (parameters to be determined) |
|
|
|
|
|
|
|
|
Now we must decide what data types to use. We began with the general concept of an entry. We refined it to include the items needed in the entry. To go any further, we must decide how we will represent these items in C++. And we must design specific algorithms for our data structure: reading in items, sorting items, and printing items. |
|
|
|
|
|
|
|
|
Two of the items are namesthat is, sequences of alphabetic characters. We can represent them as strings. The area code and phone number could be integer numbers, but we would like to store the hyphen that is between the third and fourth digits of the phone number. Therefore, the area code is an integer number but the phone number is a string. (We assume that an area code is 100 or greater so that we don't have to worry about how to print leading zeros in area codes such as 052. A Case Study Follow-Up exercise asks you to rethink this assumption.) We can represent birth dates as three integers: month, day, and year. Thus, an entry is represented by the seven components shown in Figure 14-11. |
|
|
|
|
|
|
|
|
We can create a set of parallel arrays to hold these items for all of our friends. firstName, lastName, and phoneNumber are arrays of strings; areaCode, month, day, and year are one-dimensional arrays of integers. Each |
|
|
|
|
|
|
|
|
Figure 14-11
Entry for Address Book |
|
|
|
|
|