AP CSP Big Idea 3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A, D

-->

B. I and III only

A. I and II only B. I and III only C. II and III only D. I, II, and III

idk

Consider the fo- wait where is the image?

C. A string variable named studentName and a Boolean variable named isAbsent

A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment? A. A string variable named s and a Boolean variable named a B. A string variable named s and a numeric variable named n C. A string variable named studentName and a Boolean variable named isAbsent D. A string variable named studentName and a numeric variable named numAbsences

A.

A teacher stores the most recent quiz scores for her class in the list scores. The first element in the list holds the maximum possible number of points that can be awarded on the quiz, and each remaining element holds one student's quiz score. Assume that scores contains at least two elements. Which of the following code segments will set the variable found to true if at least one student scored the maximum possible number of points on the quiz and will set found to false otherwise?

B. II only

A. I only B. II only C. I and II D. II and III

B. IF NOT hot DISPLAY hot OR humid C. IF hot OR humid DISPLAY hot

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. ("DISPLAY" is indented) A. IF hot DISPLAY hot AND humid B. IF NOT hot DISPLAY hot OR humid C. IF hot OR humid DISPLAY hot D. IF hot AND humid DISPLAY hot

C. APPEND(evenList, 2 * i) i ←← i + 1

Consider the following code segment, which is intended to store ten consecutive even integers, beginning with 2, in the list evenList. Assume that evenList is initially empty. i ←← 1 REPEAT 10 TIMES { <MISSING CODE> } Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended? A. APPEND(evenList, i) i ←← i + 2 B. i ←← i + 2 APPEND(evenList, i) C. APPEND(evenList, 2 * i) i ←← i + 1 D. i ←← i + 1 APPEND(evenList, 2 * i)

B. count1 = 2, count2 = 3

Consider the following code segment. <image> What are the values of count1 and count2 as a result of executing the code segment? A. count1 = 2, count2 = 2 B. count1 = 2, count2 = 3 C. count1 = 3, count2 = 2 D. count1 = 5, count2 = 0

C. 100 300 500

Consider the following code segment. <image> What is displayed as a result of executing the code segment? A. 1 3 5 B. 5 3 1 C. 100 300 500 D. 500 300 100

D. true true true

Consider the following code segment. <image> What is displayed as a result of executing the code segment? A. true false false B. true false true C. true true false D. true true true

C. 15 (EXPLANATION: Correct. The variables x and result are initialized to 0. Inside the loop, result is increased by x and x is increased by 1. The loop terminates when x exceeds 5. Therefore, result is assigned the sum of the integers from 0 to 5, or 15.)

Consider the following code segment. <image> What is the value of result after the code segment is executed? A. 6 B. 10 C. 15 D. 21

B. ["guitar", "drums", "bass"]

Consider the following code segment. firstList ←← ["guitar", "drums", "bass"] secondList ←← ["flute", "violin"] thirdList ←← [ ] thirdList ←← firstList firstList ←← secondList secondList ←← thirdList What are the contents of secondList after the code segment is executed? A [ ] B. ["guitar", "drums", "bass"] C. ["flute", "violin"] D. ["flute", "violin", "guitar", "drums", "bass"]

A.

REPEAT UNTIL (GoalReached ( ) ) { <MISSING CODE> }

B. FOR EACH vote IN voteList

Shoppers at a mall were asked whether they preferred wearing gloves or mittens in cold weather. Shoppers' preferences were stored in the list voteList as strings, with the string "Gloves" representing a preference for gloves and the string "Mittens" representing a preference for mittens. The following code segment is intended to traverse the list and display the number of shoppers who chose gloves and the number of shoppers who chose mittens. <image> Which of the following should replace <MISSING CODE> so that the code segment works as intended? A. IF(vote ≤ LENGTH(voteList)) B. FOR EACH vote IN voteList C. REPEAT LENGTH(voteList) TIMES D. REPEAT UNTIL(vote > LENGTH(voteList))

A. left ←← substring(oldStr, 1, n - 1) right ←← substring(oldStr, n + 1, len(oldStr)) newStr ←← concat(left, right) C. newStr ←← substring(oldStr, 1, n - 1) newStr ←← concat(newStr, substring(oldStr, n + 1, len(oldStr)))

TWO ANSWERS A. left ←← substring(oldStr, 1, n - 1) right ←← substring(oldStr, n + 1, len(oldStr)) newStr ←← concat(left, right) B. left ←← substring(oldStr, 1, n + 1) right ←← substring(oldStr, n - 1, len(oldStr)) newStr ←← concat(left, right) C. newStr ←← substring(oldStr, 1, n - 1) newStr ←← concat(newStr, substring(oldStr, n + 1, len(oldStr))) D. newStr ←← substring(oldStr, n + 1, len(oldStr)) newStr ←← concat(newStr, substring(oldStr, 1, n - 1))

B. animal ← Substring ("antelope", 5, 4) animal ← Concat ("a", animal) animal ← Concat (Substring ("jackrabbit", 1, 4), animal) C. animal ← Substring ("jackrabbit", 1, 4) animal ← Concat (animal, "a") animal ← Concat (animal, Substring ("antelope", 5, 4))

TWO ANSWERS A. animal ← Substring ("antelope", 5, 4) animal ← Concat (animal, "a") animal ← Concat (Substring ("jackrabbit", 1, 4), animal) B. animal ← Substring ("antelope", 5, 4) animal ← Concat ("a", animal) animal ← Concat (Substring ("jackrabbit", 1, 4), animal) C. animal ← Substring ("jackrabbit", 1, 4) animal ← Concat (animal, "a") animal ← Concat (animal, Substring ("antelope", 5, 4)) D. animal ← Substring ("jackrabbit", 1, 4) animal ← Concat (animal, "a") animal ← Concat (Substring ("antelope", 5, 4), animal)

A. IF RANDOM (1,4) = 1 DISPLAY "blue" ELSE IF RANDOM (1,2) = 1 DISPLAY "orange" ELSE DISPLAY "purple D. spin <-- RANDOM (1,4) IF spin = 1 DISPLAY "blue" ELSE spin <-- RANDOM (1,2) IF spin = 2 DISPLAY "orange" ELSE DISPLAY "purple

TWO ANSWERS (on each answer, everything after the first else is indented as for all the displays) A. IF RANDOM (1,4) = 1 DISPLAY "blue" ELSE IF RANDOM (1,2) = 1 DISPLAY "orange" ELSE DISPLAY "purple B. IF RANDOM (1,4) > 1 DISPLAY "blue" ELSE IF RANDOM (1,2) = 1 DISPLAY "orange" ELSE DISPLAY "purple C. spin <-- RANDOM (1,4) IF spin = 1 DISPLAY "blue" ELSE IF spin = 2 DISPLAY "orange" ELSE DISPLAY "purple D. spin <-- RANDOM (1,4) IF spin = 1 DISPLAY "blue" ELSE spin <-- RANDOM (1,2) IF spin = 2 DISPLAY "orange" ELSE DISPLAY "purple

B. REPEAT 2 TIMES

The following grid contains a robot represented as a triangle, which is initially facing right. <image> The following code segment is intended to move the robot to the gray square. <MISSING STATEMENT> { REPEAT 4 TIMES { MOVE_FORWARD() ROTATE_RIGHT() } ROTATE_LEFT() MOVE_FORWARD() ROTATE_RIGHT() } Which of the following can be used as a replacement for <MISSING STATEMENT> so that the code segment works as intended? A. REPEAT 1 TIMES B. REPEAT 2 TIMES C. REPEAT 3 TIMES D. REPEAT 4 TIMES

D. REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 2 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 3 TIMES { MOVE_FORWARD() }

The following grid contains a robot represented as a triangle, which is initially facing toward the top of the grid. The robot can move into a white or gray square but cannot move into a black region. <image> Which of the following code segments can be used to move the robot to the gray square? A. REPEAT 3 TIMES { MOVE_FORWARD() } REPEAT 2 TIMES { MOVE_FORWARD() } REPEAT 3 TIMES { MOVE_FORWARD() } B. REPEAT 8 TIMES { MOVE_FORWARD() } C. REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 2 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 3 TIMES { MOVE_FORWARD() } D. REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 2 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 3 TIMES { MOVE_FORWARD() }

D. 4

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list? A. -1 B. "hello" C. 2.5 D. 4

B. number

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

A. Bool

The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ? A. Bool B. number C. str D. list

A. (age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80))

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? A. (age ≥ 12) AND ((height ≥ 50) AND (height ≤ 80)) B. (age ≥ 12) AND ((height ≤ 50) AND (height ≥ 80)) C. (age ≥ 12) AND ((height ≤ 50) OR (height ≥ 80)) D. (age ≥ 12) OR ((height ≥ 50) AND (height ≤ 80))

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.

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. Lists often allow their size to be easily updated to hold as many data values as needed.

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.

B. cost ← 6 IF (age > 12) { cost ← cost + 2 } IF (includesTour) #(not indented) { cost ← cost + 2 } DISPLAY (cost)

(watch the indents) A. cost ← 6 IF ((age > 12) OR includesTour) { cost ←← cost + 2 } DISPLAY (cost) B. cost ← 6 IF (age > 12) { cost ← cost + 2 } IF (includesTour) #(not indented) { cost ← cost + 2 } DISPLAY (cost) C. cost ← 6 IF (age > 12) { IF (includesTour) #(indented) { cost ← cost + 2 } } DISPLAY (cost) D. cost ← 6 IF (age > 12) { cost ← cost + 2 } ELSE { IF (includesTour) #(indented) { cost ←← cost + 2 } } DISPLAY (cost)

C. First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep."

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? A. First, change all occurrences of "goats" to "sheep." Then, change all occurrences of "sheep" to "goats." B. First, change all occurrences of "goats" to "sheep." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep." C. First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "sheep" to "goats." Last, change all occurrences of "foxes" to "sheep." D. First, change all occurrences of "goats" to "foxes." Then, change all occurrences of "foxes" to "sheep." Last, change all occurrences of "sheep" to "goats."

D. (target - 10 ≤ score) AND (score ≤ target + 10)

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 ? A. (score ≤ target + 10) AND (target + 10 ≤ score) B. (target + 10 ≤ score) AND (score ≤ target - 10) C. (score ≤ target - 10) AND (score ≤ target + 10) D. (target - 10 ≤ score) AND (score ≤ target + 10)

A. Step 4 Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to 2, display

A. Step 4 Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to 2, display true. Otherwise, display false. B. Step 4 Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to position, display true. Otherwise, display false. C. Step 4 Repeat steps 2 and 3 until the value of count is greater than 2. Step 5 If position is greater than or equal to n, display true. Otherwise, display false. D. Step 4 Repeat steps 2 and 3 until the value of count is greater than n. Step 5 If count is greater than or equal to 2, display true. Otherwise, display false.

A. include <-- (floor > 10) OR (bedrooms = 3)

A. include <-- (floor > 10) OR (bedrooms = 3) B. include <-- (floor > 10) AND (bedrooms = 3) C. include <-- (floor <= 10) OR (bedrooms = 3) D. include <-- (floor <= 10) AND (bedrooms = 3)

A. initials ←← concat(prefix(firstName, 1), prefix(lastName, 1))

A. initials ←← concat(prefix(firstName, 1), prefix(lastName, 1)) B. initials ←← concat(prefix(firstName, 2), prefix(lastName, 2)) C. initials ←← prefix(concat(firstName, lastName), 1) D. initials ←← prefix(concat(firstName, lastName), 2)

B. 14

Consider the following code segment. Assume that index1 is a number between 1 and LENGTH(theList), inclusive, and index2 is a number between 2 and LENGTH(theList) - 1, inclusive. theList ←← [9, -1, 5, 2, 4, 8] x ←← theList[index1] + theList[index2] What is the largest possible value that the variable x can have after the code segment executes? A. 17 B. 14 C. 11 D. 4

A. The value of first is true, and the value of second is true.

Consider the following code segment. What are the values of first and second as a result of executing the code segment? A. The value of first is true, and the value of second is true. B. The value of first is true, and the value of second is false. C. The value of first is false, and the value of second is true. D. The value of first is false, and the value of second is false.

B. 20

Consider the following code segment. What is the value of r as a result of executing the code segment? A. 10 B. 20 C. 30 D. 40

C. 3 4

Consider the following program, which uses the variables start, end and current. What is displayed as a result of executing the program? A. 1 3 B. 3 3 C. 3 4 D. 4 4

A. The difference between borrows and returns is zero. D. The sum of borrows and returns is a positive even number.

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. A school library allows students to borrow laptops. A computer program is used to count the number of times a particular laptop has been borrowed from the library (borrows) and the number of times the same laptop has been returned to the library (returns) . Which of the following indicate that a particular laptop is not currently borrowed? Select two answers. A. The difference between borrows and returns is zero. B. The product of borrows and returns is a positive even number. C. The quotient when borrows is divided by returns is greater than 1. D. The sum of borrows and returns is a positive even number.

A. A simulation of flipping a fair coin

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 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. A simulation of flipping a fair coin B. A simulation of rolling a fair die (with sides numbered 1 through 6) C. A simulation of the temperature in a location over time D. A simulation of traffic patterns on a road

B. Replacing line 9 with ELSE

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. <image> 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? A. Replacing line 9 with IF(RANDOM(1, 4) ≥ 2) B. Replacing line 9 with ELSE C. Interchanging lines 5 and 9 D. Interchanging lines 7 and 11


Set pelajaran terkait

Chapter 13 Developmental Psychology

View Set

Chapter 4 World History LESSON 3

View Set

PANCREATIC ENZYMES and OTHER ENZYMES OF CLINICAL SIGNIFICANCE

View Set

Apex Learning Quiz Review 4.1.4 Career and College Prep

View Set

ATI RN Concept-Based Assessment Level 1 Online Practice A

View Set