Peer Instruction: Unit 4 Multiple Choice QuestionsΒΆ
- Decreases the blue component of a picture
- Incorrect! The blue component of the picture is not necessarily decreased in the for each loop. The for each loop loops through the Pixel objects in pixelArray, calls getGreen, stores getGreen into value, and then sets value into blue.
- Sets the green component of each pixel to be the same as the blue component
- Incorrect! The green component is not altered. The for each loop loops through the Pixel objects in pixelArray, calls getGreen, stores getGreen into value, and then sets value into blue.
- Sets the blue component of each pixel to be the same as the green component
- Incorrect! Although it is possible that the code is performing this action, it is more accurate that the for each loop loops through the Pixel objects in pixelArray, calls getGreen, stores getGreen into value, and then sets value into blue.
- Loops over all pixels in pixelArray. Each pO calls getGreen and stores that into value. Then sets value into blue.
- Correct! The for each loop loops through the Pixel objects in pixelArray, calls getGreen, stores getGreen into value, and then sets value into blue.
- None of the above.
- Incorrect! One of the above answers is correct. The for each loop loops through the Pixel objects in pixelArray, calls getGreen, stores getGreen into value, and then sets value into blue.
16-6-1: Which statement best describes what this code does?
Pixel[] pixelArray = this.getPixels();
int value = 0;
for (Pixel pO: pixelArray)
{
value = pO.getGreen();
pO.setBlue(value);
}
- A: Many, B: Many, C: 1, D: 1
- Incorrect! Section A and Section B are executed only once since they are not contained in any loops. Section C and D are executed many times since they are within the while loop.
- A: Many, B: Many, C: Many, D: 1
- Incorrect! Section A and Section B are executed only once since they are not contained in any loops. Section C and D are executed many times since they are within the while loop.
- A: 1, B: 1, C: Many, D: Many
- Correct! Section A and Section B are executed only once since they are not contained in any loops. Section C and D are executed many times since they are within the while loop.
- A: 1, B: 1, C: 1, D: Many
- Incorrect! Section A and Section B are executed only once since they are not contained in any loops. Section C and D are executed many times since they are within the while loop.
16-6-2: How many times is each set of code executed?
- A: 1, B: 1, C: 1, D: Many
- Incorrect! The first statement in a for loop (A), where the index variable is initialized, executes only once. The condition (B), updation (C), and body (D) of the for loop execute many times.
- A: 1, B: Many, C: 1, D: Many
- Incorrect! The first statement in a for loop (A), where the index variable is initialized, executes only once. The condition (B), updation (C), and body (D) of the for loop execute many times.
- A: 1, B: Many, C: Many, D: Many
- Correct! The first statement in a for loop (A), where the index variable is initialized, executes only once. The condition (B), updation (C), and body (D) of the for loop execute many times.
- A: Many, B: Many, C: Many, D: Many
- Incorrect! The first statement in a for loop (A), where the index variable is initialized, executes only once. The condition (B), updation (C), and body (D) of the for loop execute many times.
16-6-3: How many times is each set of code executed?
- A
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis.The outer loop iterates through the index values of the width, while the inner loop iterates through the index values of the height. The first pass of the outer loop (width) triggers all of the passes of the inner loop (height). For this reason, all of the heights (inner loop) for a given width (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from top to bottom moving rightward. In pixels, the grid system is used.
- B
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. Remember that (0,0) for pixels starts at the top left. The outer loop iterates through the index values of the width, while the inner loop iterates through the index values of the height. The first pass of the outer loop (width) triggers all of the passes of the inner loop (height). For this reason, all of the heights (inner loop) for a given width (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from top to bottom moving rightward.
- C
- Correct! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. The outer loop iterates through the index values of the width, while the inner loop iterates through the index values of the height. The first pass of the outer loop (width) triggers all of the passes of the inner loop (height). For this reason, all of the heights (inner loop) for a given width (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from top to bottom moving rightward.
- D
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. Remember that (0,0) for pixels starts at the top left. The outer loop iterates through the index values of the width, while the inner loop iterates through the index values of the height. The first pass of the outer loop (width) triggers all of the passes of the inner loop (height). For this reason, all of the heights (inner loop) for a given width (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from top to bottom moving rightward.
16-6-4: What picture most accurately describes what this code does?
Pixel p;
for (int foo = 0; foo < getWidth(); bar++)
{
for (int bar = 0; bar < getHeight(); foo++)
{
p = getPixel(foo, bar);
p.setColor(Color.BLACK);
}
}
- A
- Correct! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. The outer loop iterates through the index values of the height, while the inner loop iterates through the index values of the width. The first pass of the outer loop (height) triggers all of the passes of the inner loop (width). For this reason, all of the widths (inner loop) for a given height (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from right to left, downward.
- B
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. Remember that (0,0) for pixels starts at the top left. The outer loop iterates through the index values of the height, while the inner loop iterates through the index values of the width. The first pass of the outer loop (height) triggers all of the passes of the inner loop (width). For this reason, all of the widths (inner loop) for a given height (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from right to left, downward.
- C
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis.The outer loop iterates through the index values of the height, while the inner loop iterates through the index values of the width. The first pass of the outer loop (height) triggers all of the passes of the inner loop (width). For this reason, all of the widths (inner loop) for a given height (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from right to left, downward.
- D
- Incorrect! In pixels, the grid system is used. The width represents the x-axis and the height represents the y-axis. Remember that (0,0) for pixels starts at the top left. The outer loop iterates through the index values of the height, while the inner loop iterates through the index values of the width. The first pass of the outer loop (height) triggers all of the passes of the inner loop (width). For this reason, all of the widths (inner loop) for a given height (outer loop) are changed before moving to the next iteration of the outer loop. This motion goes from right to left, downward.
16-6-5: What picture most accurately describes what this code does?
Pixel p;
for (int bar = 0; bar < getHeight(); bar++)
{
for (int foo = 0; foo < getWidth(); foo++)
{
p = getPixel(foo, bar);
p.setColor(Color.BLACK);
}
}
- A
- Incorrect! In the first iteration, x and y are both 0 so leftP is (0,0), and rightP is (getWidth - 1 - x), which is 99 (100 - 1 - 0). In the second iteration, x is 1 and y is still 0, so leftP is (1,0) and rightP is (getWidth - 1 - x), which is 98 (100 - 1 - 1). In the third iteration, x is 2 and y is 0 so leftP is (2,0) and rightP is (getWidth - 1 - 2), which is 97 (100 - 1 - 2).
- B
- Correct! In the first iteration, x and y are both 0 so leftP is (0,0), and rightP is (getWidth - 1 - x), which is 99 (100 - 1 - 0). In the second iteration, x is 1 and y is still 0, so leftP is (1,0) and rightP is (getWidth - 1 - x), which is 98 (100 - 1 - 1). In the third iteration, x is 2 and y is 0 so leftP is (2,0) and rightP is (getWidth - 1 - 2), which is 97 (100 - 1 - 2).
- C
- Incorrect! In the first iteration, x and y are both 0 so leftP is (0,0), and rightP is (getWidth - 1 - x), which is 99 (100 - 1 - 0). In the second iteration, x is 1 and y is still 0, so leftP is (1,0) and rightP is (getWidth - 1 - x), which is 98 (100 - 1 - 1). In the third iteration, x is 2 and y is 0 so leftP is (2,0) and rightP is (getWidth - 1 - 2), which is 97 (100 - 1 - 2).
- D
- Incorrect! In the first iteration, x and y are both 0 so leftP is (0,0), and rightP is (getWidth - 1 - x), which is 99 (100 - 1 - 0). In the second iteration, x is 1 and y is still 0, so leftP is (1,0) and rightP is (getWidth - 1 - x), which is 98 (100 - 1 - 1). In the third iteration, x is 2 and y is 0 so leftP is (2,0) and rightP is (getWidth - 1 - 2), which is 97 (100 - 1 - 2).
16-6-6: What are the parameter values we use to index leftPixel and rightPixel for the first three iterations of the loop? (assume picture has a height = 50 and width = 100)
int mirrorPt = getWidth()/2;
Pixel leftP, rightP;
for (int y = 0; y < getHeight); y++)
{
for (int x = 0; x < mirrorPt; x++)
{
leftP = getPixel(x,y);
rightP = getPixel(getWidth()-1-x,y);
rightP.setColor(leftP.getColor());
}
}
You have attempted of activities on this page