Ap Classroom Unit 4
Which of the following is NOT a possible value displayed by the program?
"carrot"
The following table shows the value of expression based on the values of input1 and input2. Which of the following expressions are equivalent to the value of expression as shown in the table? Select two answers.
(NOT input1) OR (NOT input2) NOT (input1 AND input2)
To be eligible for a particular ride at an amusement park, a person must be at least 12 years old and must be between 50 and 80 inches tall, inclusive. Let age represent a person's age, in years, and let height represent the person's height, in inches. Which of the following expressions evaluates to true if and only if the person is eligible for the ride?
(age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80))
In column B, the price range represents the typical cost of a meal, where "lo" indicates under $10, "med" indicates $11 to $30, and "hi" indicates over $30. In column D, the average customer rating is set to -1.0 for restaurants that have no customer ratings. A student wants to count the number of restaurants in the spreadsheet whose price range is $30 or less and whose average customer rating is at least 4.0. For a given row in the spreadsheet, suppose prcRange contains the price range as a string and avgRating contains the average customer rating as a decimal number. Which of the following expressions will evaluate to true if the restaurant should be counted and evaluates to false otherwise?
(avgRating ≥ 4.0) AND ((prcRange = "lo") OR (prcRange = "med"))
The code fragment below is intended to display "odd" if the positive number num is odd. Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?
(num MOD 2) = 1
An office building has two floors. A computer program is used to control an elevator that travels between the two floors. Physical sensors are used to set the following Boolean variables. The elevator moves when the door is closed and the elevator is called to the floor that it is not currently on. Which of the following Boolean expressions can be used in a selection statement to cause the elevator to move?
(onFloor1 AND callTo2) OR (onFloor2 AND callTo1)
A programmer wants to determine whether a score is within 10 points of a given target. For example, if the target is 50, then the scores 40, 44, 50, 58, and 60 are all within 10 points of the target, while 38 and 61 are not. Which of the following Boolean expressions will evaluate to true if and only if score is within 10 points of target ?
(target - 10 ≤ score) AND (score ≤ target + 10)
Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?
2 3
Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Consider the following program, which uses the variables , , and . What is displayed as a result of executing the program?
3 4
The following algorithm indicates how the game is played. The game continues until the game is either won by landing on the red space or lost when the piece moves off either end of the board. Step 1:Place a game piece on a space that is not red and set a counter to 0.Step 2:If the game piece is on a yellow space, move the game piece 3 positions to the left and go to step 3. Otherwise, if the game piece is on a black space, move the game piece 1 position to the left and go to step 3. Otherwise, if the game piece is on a green space, move the game piece 2 positions to the right and go to step 3.Step 3:Increase the value of the counter by 1.Step 4:If game piece is on the red space or moved off the end of the game board, the game is complete. Otherwise, go back to step 2. If a game is begun by placing the game piece on the rightmost black space for step 1, what will be the value of the counter at the end of the game?
4
Assume that the Boolean variable x is assigned the value true and the Boolean variable y is assigned the value false. Which of the following will display the value true ? Select two answers.
A and B
In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows. If timer is less than 30, then 500 bonus points are awarded. If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded. If timer is greater than 60, then 1500 bonus points are awarded. Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ? Select two answers.
A and D
The following spinner is used in a game. The region labeled "blue" represents 1414 of the spinner. The regions labeled "orange" and "purple" are equal in size. Which of the following code segments can be used to simulate the behavior of the spinner? Select two answers.
A and D
Which of the following code segments produce the same result as the statement above for all possible values of val1 and val2 ? Select two answers.
A and D
A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?
A simulation of flipping a fair coin
A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5 and 3, the result is 0. Which of the following is the best explanation for the result?
An overflow error occurred.
A gray square represents a possible final location of the robot after the code segment is executed. Which of the following represents all possible final locations for the robot?
B
A programmer is creating an algorithm to display the cost of a ticket based on the information in the table. The programmer uses the integer variable age for the age of the ticket recipient. The Boolean variable includesTour is true when the ticket is for a guided tour and is false when the ticket is for general admission. Which of the following code segments correctly displays the cost of a ticket?
B
Assume that the Boolean variable hot is assigned the value true and the Boolean variable humid is assigned the value false. Which of the following will display the value true ? Select two answers.
B and C
The code segment below is intended to swap the values of the variables and using a temporary variable, .Which of the following can be used to replace so that the code segment works as intended?
B second temp
If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment?
Better late than never.
While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction somewhere in the code. Where could be inserted so that the code segment works as intended?
Between line 9 and line 10
A programmer is creating an algorithm to set the value of based on the information in the table. The programmer uses the integer variable for the age of the moviegoer. The Boolean variable is when the movie is 3-D and otherwise. Which of the following code segments correctly sets the value of ?
C
Consider a game in which a player flips a fair coin three times. If all three coin flips have the same result (either all heads or all tails) the player wins. Otherwise, the player loses. Which of the following code segments best simulates the behavior of the game?
D
Which of the following can be used to replace so that the procedure correctly simulates the spinner?
D
Which of the following code segments can be used to simulate the behavior of the spinner?
D
A programmer completes the user manual for a video game she has developed and realizes she has reversed the roles of goats and sheep throughout the text. Consider the programmer's goal of changing all occurrences of "goats" to "sheep" and all occurrences of "sheep" to "goats." The programmer will use the fact that the word "foxes" does not appear anywhere in the original text. Which of the following algorithms can be used to accomplish the programmer's goal?
First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."
The program segment below is intended to move a robot in a grid to a gray square. The program segment uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. The robot in each grid is represented as a triangle and is initially facing left. The robot can move into a white or gray square but cannot move into a black region.For which of the following grids does the program NOT correctly move the robot to the gray square?
Grid I only
For each grid, the program below is intended to move the robot to the gray square. The program uses the procedure Goal_Reached ( ), which evaluates to true if the robot is in the gray square and evaluates to false otherwise.For which of the grids does the program correctly move the robot to the gray square?
Grid II only
Assume that the variables alpha and beta each are initialized with a numeric value. Which of the following code segments can be used to interchange the values of alpha and beta using the temporary variable temp ?
I and III only
In mathematics, a perfect number is a type of integer. The procedure IsPerfect (num) returns true if num is a perfect number and returns false otherwise. The following program is intended to count and display the number of perfect numbers between the integers start and end, inclusive. Assume that start is less than end. The program does not work as intended. Line 1: currentNum ←← start Line 2: count ←← 0 Line 3: REPEAT UNTIL (currentNum > end) Line 4: { Line 5: count ←← count + 1 Line 6: IF (IsPerfect (currentNum)) Line 7: { Line 8: count ←← count + 1 Line 9: currentNum ←← currentNum + 1 Line 10: } Line 11: currentNum ←← currentNum + 1 Line 12: } Line 13: DISPLAY (count) Which two lines of code should be removed so that the program will work as intended? Select two answers
Line 9 Line 5
Which of the following Boolean expressions are equivalent to the expression ? Select two answers.
Not (num < 15) (num > 15) OR (num = 15)
What is displayed as a result of running the program?In the program below, the initial value of x is 5 and the initial value of y is 10.
November
Which of the following can be used to replace so that the simulation works as intended?
Random (1, 100) <= 75
Which of the following can be used to replace missing condition in line 4 so that the program works as intended? Select two answers.
Random (1, 5) = 1 Random (1, 10) <= 2
In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount ←← 0 Line 2: yCount ←← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM(1, 4) = 1) Line 6: { Line 7: xCount ←← xCount + 1 Line 8: } Line 9: IF(RANDOM(1, 4) > 1) Line 10: { Line 11: yCount ←← yCount + 1 Line 12: } Line 13: } Line 14: DISPLAY("Result X occurred") Line 15: DISPLAY(xCount) Line 16: DISPLAY("times and result Y occurred") Line 17: DISPLAY(yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment?
Replacing line 9 with ELSE
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?
Step 3: Display the remainder of number divided by 10 and store the integer quotient in number.
A video-streaming Web site keeps count of the number of times each video has been played since it was first added to the site. The count is updated each time a video is played and is displayed next to each video to show its popularity. At one time, the count for the most popular video was about two million. Sometime later, the same video displayed a seven-digit negative number as its count, while the counts for the other videos displayed correctly. Which of the following is the most likely explanation for the error?
The count for the video became larger than the maximum value allowed by the data type used to store the count.
Which of the following are benefits of using well-named variables in a computer program? Select two answers.
The program will be easier for people to read. The program will be easier to modify in the future.
What are the values of first and second as a result of executing the code segment?
first = 100, second = 100
Central High School keeps a database of information about each student, including the numeric variables numberOfAbsences and gradePointAverage. The expression below is used to determine whether a student is eligible to receive an academic award. (numberOfAbsences ≤ 5) AND (gradePointAverage > 3.5) Which of the following pairs of values indicates that a student is eligible to receive an academic award?
numberOfAbsences = 5, gradePointAverage = 3.8
In the following program, assume that the variable n has been initialized with an integer value. Which of the following is NOT a possible value displayed by the program?
out of range
The following code segment is intended to set max equal to the maximum value among the integer variables x, y, and z. The code segment does not work as intended in all cases.Which of the following initial values for x, y, and z can be used to show that the code segment does not work as intended?
x = 3, y = 2, z = 1