In: Computer Science
Quiz 5
1. Use the following definitions to “fill” the arrays. Write in both the data (in the grid) and the index (below the grid). Cross out any unused locations. [6 each]
a. final int SIZE = 7;
int nums [SIZE] = {5, 1, 3, 8, 4};
nums
|
|||||||||
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
b. final int SIZE = 5;
float values[SIZE] = {5.7, 3.2, 9.4, 2.5, 8.5};
values
|
|||||||||
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
c. char letters[] = {'Z', 'Y', 'X', 'W', 'V', 'U'};
letters
|
|||||||||
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
2. Follow the segment of code, and use the grid to keep track of the array. Below, state only the requested values in the array at the conclusion of the code segment.
x
|
|||||||||
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
[ ] |
final int SIZE = 6;
int x[SIZE] = {5, 7, 6, 2};
x[2] = x[1];
x[5] = 28;
x[1] = 15;
x[3] = x[1] * 2;
x[1] = 32;
x[2] = x[4];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
a. x[1] = _____________ [1]
b. x[2] = _____________ [1]
c. x[3] = _____________ [1]
d. x[4] = _____________ [1]
e. x[5] = _____________ [1]
f. x[8] = _____________ [1]
1.
a.
final int SIZE = 7;
int nums [SIZE] = {5, 1, 3, 8, 4};
nums
0 |
1 |
2 |
3 |
4 |
5 |
6 |
X |
X |
X |
[ 5 ] |
[ 1 ] |
[ 3 ] |
[ 8 ] |
[ 4 ] |
[ 0 ] |
[ 0 ] |
[ X ] |
[ X ] |
[ X ] |
b. final int SIZE = 5;
float values[SIZE] = {5.7, 3.2, 9.4, 2.5, 8.5};
values
0 |
1 |
2 |
3 |
4 |
X |
X |
X |
X |
X |
[ 5.7 ] |
[ 3.2 ] |
[ 9.4 ] |
[ 2.5 ] |
[ 8.5 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
c. char letters[] = {'Z', 'Y', 'X', 'W', 'V', 'U'};
letter
0 |
1 |
2 |
3 |
4 |
5 |
X |
X |
X |
X |
[ 'Z' ] |
[ 'Y' ] |
[ 'X' ] |
[ 'W' ] |
[ 'V' ] |
[ 'U' ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
=======================================================================
2.
final int SIZE = 6;
int x[SIZE] = {5, 7, 6, 2};
[ 5 ] |
[ 7 ] |
[ 6 ] |
[ 2 ] |
[ 0 ] |
[ 0 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[2] = x[1];
[ 5 ] |
[ 7 ] |
[ 7 ] |
[ 2 ] |
[ 0 ] |
[ 0 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[5] = 28;
[ 5 ] |
[ 7 ] |
[ 7 ] |
[ 2 ] |
[ 0 ] |
[ 28 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[1] = 15;
[ 5 ] |
[ 15 ] |
[ 7 ] |
[ 2 ] |
[ 0 ] |
[ 28 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[3] = x[1] * 2;
[ 5 ] |
[ 15 ] |
[ 7 ] |
[ 30 ] |
[ 0 ] |
[ 28 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[1] = 32;
[ 5 ] |
[ 32 ] |
[ 7 ] |
[ 30 ] |
[ 0 ] |
[ 28 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
x[2] = x[4];
[ 5 ] |
[ 32 ] |
[ 0 ] |
[ 30 ] |
[ 0 ] |
[ 28 ] |
[ X ] |
[ X ] |
[ X ] |
[ X ] |
a. x[1] = ____32_________ [1]
b. x[2] = _____0________ [1]
c. x[3] = _____30________ [1]
d. x[4] = _____0________ [1]
e. x[5] = _____28________ [1]
f. x[8] = _____X________ [1]