rewrite the declaration of twoDim without referring to type OneDimType. (pp. 723724)
9. How many components does the following data type contain? (pp. 724727)
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]
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.