|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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. |
|
|
|
 |
|
|
|
|
a. A 24-element float array |
|
|
|
 |
|
|
|
|
b. A 500-element int array |
|
|
|
 |
|
|
|
|
c. A 50-element double precision floating point array |
|
|
|
 |
|
|
|
|
d. A 10-element char array |
|
|
|
|
|
|
|
|
4. Write a code fragment to do the following tasks: |
|
|
|
 |
|
|
|
|
a. Declare a constant named CLASS_SIZE representing the number of students in a class. |
|
|
|
 |
|
|
|
|
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: |
|
|
|
 |
|
|
|
|
a. Declare an enumeration type BirdType made up of bird names. |
|
|
|
 |
|
|
|
|
b. Declare an int array sightings that is to be indexed by BirdType. |
|
|
|
|
|
|
|
|
6. Given the declarations |
|
|
|
 |
|
|
|
|
const int MAX_LENGTH = 100;
enum Colors
{
BLUE, GREEN, GOLD, ORANGE, PURPLE, RED, WHITE, BLACK
}; |
|
|
|
|
|