Test Corrections
None
- Question 11
- Answer
- Question 14
- Answer
- Question 23
- Answer
- Question 64
- Answer
- Question 65
- Answer
- Question 67
- Answer
Question 11
A color in a computing application is represented by an RGB triplet that describes the amount of red, green, and blue, respectively, used to create the desired color. A selection of colors and their corresponding RGB triplets are shown in the following table. Each value is represented in decimal (base 10).
According to information in the table, what color is represented by the binary RGB triplet (11111111, 11111111, 11110000) ?
Answer
The binary number 11111111 is equal to , or 255. The binary number 11110000 is equal to, or 240. Therefore, the given binary triplet represents the color ivory. This makes sense as the only binary sequence that could possibly equal ivory would be the above.
Question 14
The following algorithm is intended to take a positive integer as input and display its individual digits in order from right to left. For example, if the input is 512, the algorithm should produce the output 2 1 5. Step 3 of the algorithm is missing.
Step 1: Input a positive integer from the user and store it in the variable number.
Step 2: Divide number by 10 and record the integer quotient and the remainder. The integer quotient is the quotient with any part after the decimal point dropped. For example, when 127 is divided by 10, the quotient is 12.7, the integer quotient is 12 and the remainder is 7.
Step 3: (missing step)
Step 4: Repeat steps 2 and 3 until number is 0.
Which of the following can be used as step 3 so that the algorithm works as intended?
Answer
With this step, the algorithm will repeatedly perform integer division on number, printing the remainder (the rightmost digit) until number is 0. For example, if the input is 512, the algorithm will display the remainder 2, then store the integer quotient 51 in number, then display the remainder 1, then store the integer quotient 5 in number, then display the remainder 5, then store the integer quotient 0 in number, then terminate.
This makes sense because the algorithm breaks down a number by repeatedly finding and displaying its rightmost digit, providing a clear and organized way to understand its composition and structure through the process of integer division.
Question 23
A flowchart is a way to visually represent an algorithm. The flowchart below is used by an application to set the Boolean variable available to true under certain conditions. The flowchart uses the Boolean variable weekday and the integer variable miles.
Which of the following statements is equivalent to the algorithm in the flowchart?
Answer
The flowchart sets available to true whenever weekday is true and miles is less than 20, and sets available to false otherwise. This code statement provides the same functionality.
This makes sense because it ensures that the availability is true only on weekdays with a travel distance less than 20 miles, thus si a straightforward and logical condition for determining accessibility.
Question 64
The following procedure is intended to return the value of x times y, where x and y are integers. Multiplication is implemented using repeated additions. For which of the following procedure calls does the procedure NOT return the intended value?
Answer
Since y is initially negative, the loop condition count ≥ y is initially true, so the body of the loop is never executed and 0 is returned.
This makes sense because the loop condition count ≥ y starts as true due to the initial negative value of y, and since the loop body is not executed, the function returns 0 without any further continuation.
Question 65
A program contains the following procedures for string manipulation.
Which of the following can be used to store the string “jackalope” in the string variable animal ?
Answer
This code segment stores the substring “lope” in animal. It then concatenates “a” and “lope”, storing the result “alope” in animal. Lastly, it concatenates the substring “jack” and “alope”, storing the result “jackalope” in animal. This makes sense because it starts with “lope,” adds “a” to create “alope,” and then combines “jack” with “alope” to form the word “jackalope” in the variable “animal.”
This code segment stores the substring “jack” in animal. It then concatenates “jack” and “a”, storing the result “jacka” in animal. Lastly, it concatenates “jacka” and the substring “lope”, storing the result “jackalope” in animal. This makes sense because it begins with “jack,” adds “a” to become “jacka,” and then combines “jacka” with the substring “lope” to form “jackalope” in the variable “animal.”
Question 67
The procedure NumOccurrences is intended to count and return the number of times targetWord appears in the list wordList. The procedure does not work as intended.
For which of the following code segments will the call to NumOccurrences NOT return the intended value?
Answer
For this code segment, count is increased to 1 the first time “maple” is encountered in the list. However, count is reset to 0 when the code segment moves to the next list element. This causes the procedure to return 0 instead of the intended result 1. For this code segment, count is increased to 1 the first time “birch” is encountered in the list. However, count is reset to 0 when the code segment moves to the next list element. The last time “birch” is encountered in the list, count is again increased to 1, causing the procedure to return 1 instead of the intended result 2.
This makes sense because, in both cases, the count is reset to 0 when moving to the next element, leading to undesired outcomes in the procedure. For “maple,” it returns 0 instead of 1, and for “birch,” it returns 1 instead of 2 .