< previous page page_639 next page >

Page 639
notes, and the component type is float. Finally, show an example of a For loop that prints out the contents of the array, (pp. 610-613)
Answers
 1. Boolean quiz[12];
 2. int (or perhaps short)
 3. firstName[0] = 'A';
 4. cout <<< firstName[13];
 5. for (index = 0; index < MAX_LENGTH; index++)
        firstName[index] = ' ';
 6. int oddNums[5] = {1, 3, 5, 7, 9};
 7. a. void SomeFunc( float x[] )
    b. void SomeFunc( const float x[] )
 8. for (index = 0; index < length; index++)
        cout << firstName[index];
 9. long number[100];         // Student numbers for 100 students
    GenderType gender[100];   // Genders for the same 100 students
10. enum NoteType {A, B, C, D, E, F, G};
    float noteVal[7];
    NoteType index;

    for (index = A; index <= G; index = NoteType (index +1))
        cout << noteVal[index] << endl;
Exam Preparation Exercises
1. Every component in an array must have the same type, and the number of components is fixed at compile time. (True or False?)
2. The components of an array must be of an integral type. (True or False?)
3. Declare one-dimensional arrays according to the following descriptions.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. A 24-element float array
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. A 500-element int array
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. A 50-element double precision floating point array
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. A 10-element char array
4. Write a code fragment to do the following tasks:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Declare a constant named CLASS_SIZE representing the number of students in a class.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Declare an array quizAvg of size CLASS_SIZE whose components will contain quiz score averages (floating point).
5. Write a code fragment to do the following tasks:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Declare an enumeration type BirdType made up of bird names.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Declare an int array sightings that is to be indexed by BirdType.
6. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
const int MAX_LENGTH = 100;

enum Colors
{
    BLUE, GREEN, GOLD, ORANGE, PURPLE, RED, WHITE, BLACK
};

 
< previous page page_639 next page >