AP CSP QUESTIONS

¡Supera tus tareas y exámenes ahora con Quizwiz!

2. Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3 ? Select two answers. (A) Step 1: Set x to 0. Step 2: Increment x by 1. Step 3: If x is not divisible by 3, then display x. Step 4: Repeat steps 2 and 3 until x is 20. (B) Step 1: Set x to 0. Step 2: If x is divisible by 3, then display x. Step 3: Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20. (C) Step 1: Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x. Step 3: Increment x by 1. Step 4: Repeat steps 2 and 3 until x is 20. (D) Step 1: Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x. Step 3: Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20.

(A) Step 1: Set x to 0. Step 2: Increment x by 1. Step 3: If x is not divisible by 3, then display x. Step 4: Repeat steps 2 and 3 until x is 20. (D) Step 1: Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x. Step 3: Increment x by 1. Step 4: Repeat steps 2 and 3 until x is greater than 20.

3. Which of the following is a benefit of using a list as a data abstraction in a program? (A) Lists often allow their size to be easily updated to hold as many data values as needed. (B) Lists convert all elements to strings so that they can be inspected character-by-character. (C) Lists prevent duplicate data values from appearing in the list. (D) Lists are used to store all input data so that there is a running record of all user input.

(A) Lists often allow their size to be easily updated to hold as many data values as needed.

2. The grid below contains a robot represented as a triangle, initially facing right. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise? REPEAT UNTIL (GoalReached ()) { <MISSING CODE> } Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square? (A) REPEAT UNTIL (CAN_MOVE (forward) = false) { ROTATE_RIGHT () } MOVE_FORWARD () (B) REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT () (C) REPEAT UNTIL (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD () (D) REPEAT UNTIL (CAN_MOVE (right)) { MOVE_FORWARD () } ROTATE_RIGHT ()

(B) REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT ()

Which of the following is an advantage of a lossless compression algorithm over a lossy compression algorithm? (A) A lossless compression algorithm can guarantee that compressed information is kept secure, while a lossy compression algorithm cannot. (B) A lossless compression algorithm can guarantee reconstruction of original data, while a lossy compression algorithm cannot. (C) A lossless compression algorithm typically allows for faster transmission speeds than does a lossy compression algorithm. (D) A lossless compression algorithm typically provides a greater reduction in the number of bits stored or transmitted than does a lossy compression algorithm.

(B) A lossless compression algorithm can guarantee reconstruction of original data, while a lossy compression algorithm cannot.

4. A digital photo file contains data representing the level of red, green, and blue for each pixel in the photo. The file also contains metadata that describes the date and geographic location where the photo was taken. For which of the following goals would analyzing the metadata be more appropriate than analyzing the data? (A) Determining the likelihood that the photo is a picture of the sky (B) Determining the likelihood that the photo was taken at a particular public event (C) Determining the number of people that appear in the photo (D) Determining the usability of the photo for projection onto a particular color background

(B) Determining the likelihood that the photo was taken at a particular public event

4. A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation? (A) Keeping the numeric values in a list makes it easier to round a number to the nearest integer. (B) Keeping the numeric values in a list makes it easier to apply the same computation to every data element. (C) Keeping the numeric values in a list makes it easier to prevent a program from unintentionally changing the value of a variable. (D) Keeping the numeric values in a list makes it easier to prevent a program from attempting to access an index beyond the length of the list.

(B) Keeping the numeric values in a list makes it easier to apply the same computation to every data element.

1.Which of the following are benefits of using well-named variables in a computer program? Select two answers. (A) The program will run faster. (B) The program will be easier for people to read. (C) The program will have a greater data storage capacity. (D) The program will be easier to modify in the future.

(B) The program will be easier for people to read. (D) The program will be easier to modify in the future.

2. The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ? (A) Boolean (B) number (C) string (D) list

(B) number

5. Central High School keeps a database of information about each student, including the numeric variables number Of Absences and grade Point Average. 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? (A) numberOfAbsences = 3, gradePointAverage = 3.5 (B) numberOfAbsences = 5, gradePointAverage = 3.8 (C) numberOfAbsences = 6, gradePointAverage = 3.4 (D) numberOfAbsences = 6, gradePointAverage = 3.6

(B) numberOfAbsences = 5, gradePointAverage = 3.8

In the following procedure, assume that the parameter x is an integer. Which of the following best describes the behavior of the procedure? (A) It displays nothing if x is negative and displays true otherwise. (B) It displays nothing if x is negative and displays false otherwise. (C) It displays true if x is negative and displays nothing otherwise. (D) It displays true if x is negative and displays false otherwise.

(C) It displays true if x is negative and displays nothing otherwise.

5. Which of the following are benefits of procedural abstraction? Select two answers. (A) Procedural abstraction prevents programmers from accidentally using the intellectual property of other programmers. (B) Procedural abstraction eliminates the need for programmers to document their code. (C) Procedural abstraction makes it easier for people to read computer programs. (D) Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

(C) Procedural abstraction makes it easier for people to read computer programs. (D) Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

Which of the following best describes a direct benefit in using redundant routing on the Internet? (A) Redundancy enables messages to be transmitted with as few packets as possible. (B) Redundancy enables network devices to communicate with as few network connections as possible. (C) Redundancy often allows messages to be sent on the network even if some network devices or connections have failed. (D) Redundancy prevents network communications from being intercepted by unauthorized individuals.

(C) Redundancy often allows messages to be sent on the network even if some network devices or connections have failed.

In a certain computer program, two positive integers are added together, resulting in an overflow error. Which of the following best explains why the error occurs? (A) The program attempted to perform an operation that is considered an undecidable problem. (B) The precision of the result is limited due to the constraints of using a floating-point representation. (C) The program can only use a fixed number of bits to represent integers; the computed sum is greater than the maximum representable value. (D) The program cannot represent integers; the integers are converted into decimal approximations, leading to rounding errors.

(C) The program can only use a fixed number of bits to represent integers; the computed sum is greater than the maximum representable value.

3. A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifications for the algorithm are as follows. • The gate should not open when the time is outside of business hours. • The motor should not turn on unless the gate sensor is activated. • The motor should not turn on if the gate is already open. Which of the following algorithms can be used to open the gate under the appropriate conditions? (A) Check if the time is outside of business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is closed. If it is, turn on the motor. (B) Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is, turn on the motor. (C) Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is not, check if the gate is open. If it is not, turn on the motor. (D) Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.

(D) Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.

4. A car manufacturer uses simulation software during the design process for a new car. Which of the following are reasons to use simulation software in this context? I. Using simulation software can save the company money by helping to compare designs early in the process, before prototype cars are built. II. Using simulation software can help to identify safety issues by providing data about how different mechanical components will interact in a wide variety of situations. III. The manufacturer can present simulation software to customers to demonstrate different design possibilities. (A) I and II only (B) I and III only (C) II and III only (D) I, II, and III

(D) I, II, and III

5. Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A programmer is developing a word game. The programmer wants to create an algorithm that will take a list of words and return a list containing the first letter of all words that are palindromes (words that read the same backward or forward). The returned list should be in alphabetical order. For example, if the list contains the words the returned list would contain(because , , and are palindromes).The programmer knows that the following steps are necessary for the algorithm but is not sure in which order they should be executed. Executing which of the following sequences of steps will enable the algorithm to work as intended? I. First shorten, then keep palindromes, then sort II. First keep palindromes, then shorten, then sort III. First sort, then keep palindromes, then shorten (A) I only (B) II only (C) I and III (D) II and III

(D) II and III

Consider the following code segment. Which of the following best describes the behavior of the code segment? (A) The code segment displays the value of by initializing result to 2 and then multiplying result by 3 a total of five times. (B) The code segment displays the value of by initializing result to 2 and then multiplying result by 5 a total of three times. (C) The code segment displays the value of by initializing result to 2 and then multiplying result by 3 a total of five times. (D) The code segment displays the value of by initializing result to 2 and then multiplying result by 5 a total of three times.

(D) The code segment displays the value of by initializing result to 2 and then multiplying result by 5 a total of three times.

Which of the following best explains the ability to solve problems algorithmically? (A) Any problem can be solved algorithmically, though some algorithmic solutions may require humans to validate the results. (B) Any problem can be solved algorithmically, though some algorithmic solutions must be executed on multiple devices in parallel. (C) Any problem can be solved algorithmically, though some algorithmic solutions require a very large amount of data storage to execute. (D) There exist some problems that cannot be solved algorithmically using any computer.

(D) There exist some problems that cannot be solved algorithmically using any computer.

4. A student's overall course grade in a certain class is based on the student's scores on individual assignments. The course grade is calculated by dropping the student's lowest individual assignment score and averaging the remaining scores. For example, if a particular student has individual assignment scores of 85, 75, 90, and 95, the lowest score (75) is dropped. The calculated course grade is (85 + 90 + 95)/3=90 A programmer is writing a program to calculate a student's course grade using the process described. The programmer has the following procedures available. Procedure Call Explanation Min (numList) Returns the minimum value in the list numList Sum (numList) Returns the sum of the values in the list numList The student's individual assignment scores are stored in the list scores. Which of the following can be used to calculate a student's course grade and store the result in the variable finalGrade? (A) finalGrade Sum (scores) / LENGTH (scores) finalGrade finalGrade - Min (scores) (B) finalGrade Sum (scores) / (LENGTH (scores) - 1) finalGrade finalGrade - Min (scores) (C) finalGrade Sum (scores) - Min (scores) finalGrade finalGrade / LENGTH (scores) (D) finalGrade Sum (scores) - Min (scores) finalGrade finalGrade / (LENGTH (scores) - 1)

(D) finalGrade Sum (scores) - Min (scores) finalGrade finalGrade / (LENGTH (scores) - 1)

3. Consider a game where a player spins a wheel divided into four identical sections, labeled A, B, C, and D. If the player spins A, the score is 10. If the player spins B, the score is 5. If the player spins C or D, the score is -1. The following code segment is intended to implement the game. Which of the following could be used as a replacement for <MISSING STATEMENT> so the code segment works as intended? A. B. C. D.

B.


Conjuntos de estudio relacionados

Chapter 10. Permissions and Ownership

View Set

C Programming Exam Review (Chapter 3)

View Set

How to Make the Most of The Little Seagull

View Set

NEETS MODULE 13-INTRO TO NUMBERS SYSTEMS AND LOGIC CIRCUITS; CH. 1

View Set

AP Biology Chapter 19 Campbell Questions

View Set