< previous page page_760 next page >

Page 760
8. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
typedef int OneDimType[100];

OneDimType twoDim[40];
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
rewrite the declaration of twoDim without referring to type OneDimType. (pp. 723724)
9. How many components does the following data type contain? (pp. 724727)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
const int SIZE = 10;
typedef char FourDim[SIZE][SIZE][SIZE][SIZE-1];
10. Write a program fragment that fills a variable of type FourDim, named quick, with blanks. (pp. 724727)
11. Suppose you are writing a program to process a table of employee numbers, names, and pay rates. Is a two-dimensional array an appropriate data structure for this problem? Explain. (pp. 727728)
Answers 1. float plan[30][10]; 2. plan[13][7] = 27.3;
 3. for (row = 0; row < 30; row++) 4. for (col = 0; col < 10; col++)
 5. for (row = 0; row < 30; row++)
        for (col = 0; col < 10; col++)
            plan[row][col] = 0.0;
 6. for (row = 0; row < 30; row++)
    {
        for (col = 0; col < 10; col++)
            cout << setw(8) << plan[row][col];
        cout << endl;
    }
 7. Either
         float someArray[30][10]
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
   or
         float someArray[][10]
 8. 
int twoDim[40][100]; 9. Nine thousand (10 * 10 * 10 * 9)
10. for (dim1 = 0; dim1 < SIZE; dim1++)
        for (dim2 = 0; dim2 < SIZE; dim2++)
            for (dim3 = 0; dim3 < SIZE; dim3++)
                for (dim4 = 0; dim4 < SIZE - 1; dim4++)
                    quick[dim1][dim2][dim3][dim4] = ' ';
11. A two-dimensional array is inappropriate because the data types of the columns are
       not the same. Parallel arrays are appropriate in this case.
Exam Preparation Exercises
1. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
const int NUM_WEEKS = 5;
const int NUM_TEAMS = 6;

int tickets[NUM_TEAMS][NUM_WEEKS];

 
< previous page page_760 next page >