0% found this document useful (0 votes)
2K views48 pages

T1-Mock Answers 2

The document provides a scoring guide for a mock AP Computer Science Principles exam. It includes 10 multiple choice questions that test concepts related to algorithms, data types, variables, conditionals, and sequencing. The questions cover topics such as identifying the correct algorithm to find the earliest birthday, updating maximum and minimum scores, representing data with appropriate data types, using variables, and writing code segments to model real-world scenarios.

Uploaded by

Amira Alwahshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views48 pages

T1-Mock Answers 2

The document provides a scoring guide for a mock AP Computer Science Principles exam. It includes 10 multiple choice questions that test concepts related to algorithms, data types, variables, conditionals, and sequencing. The questions cover topics such as identifying the correct algorithm to find the earliest birthday, updating maximum and minimum scores, representing data with appropriate data types, using variables, and writing code segments to model real-world scenarios.

Uploaded by

Amira Alwahshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

AP COMPUTER SCIENCE PRINCIPLES Scoring Guide

Term 1 - Mock 1

1. Suppose a large group of people in a room were all born in the same year. Consider the following three algorithms,
which are each intended to identify the people in the room who have the earliest birthday based on just the month
and day. For example, a person born on February 10 is considered to have an earlier birthday than a person born on
March 5. Which of the three algorithms will identify the correct people?

I. All the people in the room stand up. All standing people form pairs where possible, leaving at most one
person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the
other person in the pair sits down. If there is a tie, both people sit down. Any individual not part of a
pair remains standing. Continue doing this until only one person remains standing. That person has the
earliest birthday.
II. All the people in the room stand up. All standing people form pairs with another standing person that
they have not previously been paired with where possible, leaving at most one person not part of a pair.
For each pair, the person with the earlier birthday remains standing, while the other person in the pair
sits down. If there is a tie, both people in the pair remain standing. Any individual not part of a pair
remains standing. Continue doing this until only one person remains standing or all persons standing
have the same birthday. Anyone still standing has the earliest birthday.
III. Beginning with the number 1, ask if anyone was born on that day of any month. Continue with the
numbers 2, 3, and so on until a positive response is received. If only one person responds, that person
has the earliest birthday. If more than one person responds, determine which person was born in the
earliest month, and that person or those persons have the earliest birthday.
(A) I only
(B) II only
(C) I and II
(D) II and III

2. A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most
recent score obtained, which of the following algorithms correctly updates the values of the maximum and the
minimum?
If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is greater
(A)
than the maximum, set the maximum equal to num.
If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than
(B)
the maximum, set the maximum equal to num.
If num is less than the minimum, set the minimum equal to num. Otherwise, if num is less than the
(C)
maximum, set the maximum equal to num.
If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is less than
(D)
the maximum, set the maximum equal to num.

AP Computer Science Principles Page 1 of 48


Scoring Guide

Term 1 - Mock 1

3. 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?

Page 2 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

REPEAT UNTIL (CAN_MOVE (forward) = false)


{
(A) ROTATE_RIGHT ()
}
MOVE_FORWARD ()
REPEAT UNTIL (CAN_MOVE (forward) = false)
{
(B) MOVE_FORWARD ()
}
ROTATE_RIGHT ()
REPEAT UNTIL (CAN_MOVE (right))
{
(C) ROTATE_RIGHT ()
}
MOVE_FORWARD ()
REPEAT UNTIL (CAN_MOVE (right))
{
(D) MOVE_FORWARD ()
}
ROTATE_RIGHT ()

AP Computer Science Principles Page 3 of 48


Scoring Guide

Term 1 - Mock 1

4. 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 flowchart is a way to visually represent an algorithm. The flowchart below is used by an apartment rental Web
site to set the variable to for apartments that meet certain criteria.

Which of the following statements is equivalent to the algorithm in the flowchart?

(A)

(B)

(C)

(D)

Page 4 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

5. 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

6. 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) Boolean
(B) number
(C) string
(D) list

7. 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

8. In a certain game, the integer variable bonus is assigned a value based on the value of the integer variable
score.

• If score is greater than 100, bonus is assigned a value that is 10 times score.
• If score is between 50 and 100 inclusive, bonus is assigned the value of score.
• If score is less than 50, bonus is assigned a value of 0.

Which of the following code segments assigns bonus correctly for all possible integer values of score ?

Select two answers.

AP Computer Science Principles Page 5 of 48


Scoring Guide

Term 1 - Mock 1

IF(score > 100)


{
bonus ← score * 10
}
ELSE
{
IF(score ≥ 50)
(A) {
bonus ← score
}
ELSE
{
bonus ← 0
}
}
IF(score ≥ 50)
{
IF(score > 100)
{
bonus ← score * 10
}
ELSE
(B) {
bonus ← 0
}
}
ELSE
{
bonus ← score
}
IF(score < 50)
{
bonus ← 0
}
ELSE
{
IF(score ≥ 50)
(C) {
bonus ← score
}
ELSE
{
bonus ← score * 10
}
}
IF(score < 50)
{
bonus ← 0
}
(D) ELSE
{
IF(score > 100)
{

Page 6 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

bonus ← score * 10
}
ELSE
{
bonus ← score
}
}

9. The cost of a customer’s electricity bill is based on the number of units of electricity the customer uses.

• For the first 25 units of electricity, the cost is $5 per unit.


• For units of electricity after the first 25, the cost is $7 per unit.

Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of
using numUnits units of electricity?

(A)

(B)

(C)

(D)

AP Computer Science Principles Page 7 of 48


Scoring Guide

Term 1 - Mock 1

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?


(A) 1 1
(B) 1 2
(C) 2 3
(D) 3 2

11. 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?


(A)

(B)

(C)

(D)

Page 8 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

12. 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.

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.

13. The following table shows the value of expression based on the values of input1 and input2.

Value of input1 Value of input2 Value of expression


true true false
true false true
false true true
false false true

Which of the following expressions are equivalent to the value of expression as shown in the table?

Select two answers.


(A) (NOT input1) OR (NOT input2)

(B) (NOT input1) AND (NOT input2)


(C) NOT (input1 OR input2)

(D) NOT (input1 AND input2)

14. 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?

AP Computer Science Principles Page 9 of 48


Scoring Guide

Term 1 - Mock 1

(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

Page 10 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

15. The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially
facing toward the top of the grid.

Consider the procedure below.

AP Computer Science Principles Page 11 of 48


Scoring Guide

Term 1 - Mock 1

Which of the following code segments will move the robot to the gray square along the path indicated by the
arrows?

Page 12 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

(D)

AP Computer Science Principles Page 13 of 48


Scoring Guide

Term 1 - Mock 1

16. Consider the code segment below.

If the variables onTime and absent both have the value false, what is displayed as a result of running the code
segment?
(A) Is anyone there?
(B) Better late than never.
(C) Hello. Is anyone there?
(D) Hello. Better late than never.

17. 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?
(A) (num MOD 1) = 0
(B) (num MOD 1) = 1
(C) (num MOD 2) = 0
(D) (num MOD 2) = 1

Page 14 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

18. The diagram below shows a circuit composed of two logic gates labeled OR and AND. Each gate takes two inputs
and produces a single output.

If the inputs A and C are both true, which of the following best describes the output of the AND gate?

(A) The output will be true no matter what the value of input B is.
(B) The output will be false no matter what the value of input B is.
(C) The output will be true if input B is true; otherwise it will be false.
(D) The output will be false if input B is true; otherwise it will be true.

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 .

19. 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?

AP Computer Science Principles Page 15 of 48


Scoring Guide

Term 1 - Mock 1

finalGrade Sum (scores) / LENGTH (scores)


(A) finalGrade finalGrade - Min (scores)
finalGrade Sum (scores) / (LENGTH (scores) - 1)
(B) finalGrade finalGrade - Min (scores)
finalGrade Sum (scores) - Min (scores)
(C) finalGrade finalGrade / LENGTH (scores)
finalGrade Sum (scores) - Min (scores)
(D) finalGrade finalGrade / (LENGTH (scores) - 1)

Page 16 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

20. The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the
center square and facing toward the top of the grid.

The following code segment is used to move the robot in the grid.

count 1
REPEAT 4 TIMES
{
REPEAT count TIMES
{
MOVE_FORWARD()
}
ROTATE_LEFT()
count ← count + 1
}

Which of the following code segments will move the robot from the center square along the same path as the code
segment above?

AP Computer Science Principles Page 17 of 48


Scoring Guide

Term 1 - Mock 1

count 0
REPEAT 4 TIMES
{
count ← count + 1
REPEAT count TIMES
(A) {
MOVE_FORWARD()
}
ROTATE_LEFT()
}
count 0
REPEAT 4 TIMES
{
count ← count + 1
ROTATE_LEFT()
(B) REPEAT count TIMES
{
MOVE_FORWARD()
}
}
count 0
REPEAT 4 TIMES
{
REPEAT count TIMES
{
(C) ROTATE_LEFT()
}
MOVE_FORWARD()
count ← count + 1
}
count 0
REPEAT 4 TIMES
{
ROTATE_LEFT()
REPEAT count TIMES
(D) {
MOVE_FORWARD()
}
count ← count + 1
}

Page 18 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

21. Directions: The question or incomplete statement below is followed by four suggested answers or
completions. Select the one that is best in each case.

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially
facing right.

Consider the procedures below.

Which of the following code segments will move the robot to the gray square?

AP Computer Science Principles Page 19 of 48


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

(D)

22. Directions: The question or incomplete statement below is followed by four suggested answers or
completions. Select the one that is best in each case.

The code segment below is intended to display all multiples of 5 between the values and , inclusive.
For example, if has the value and has the value , the code segment should display the values
, , , and . Assume that and are multiples of 5 and that is less than .

Which of the following could replace in line 2 so that the code segment works as
intended?

Page 20 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(A)
(B)

(C)

(D)

23. Directions: The question or incomplete statement below is followed by four suggested answers or
completions. Select the one that is best in each case.

The grid below contains a robot represented as a triangle, initially facing up. The robot can move into a white or
gray square but cannot move into a black region.

The code segment below uses the procedure , which evaluates to if the robot is in the
gray square and evaluates to otherwise.

Which of the following replacements for can be used to move the robot to the gray square?

AP Computer Science Principles Page 21 of 48


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

(D)

Page 22 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

24. Consider the following program code.

Which of the following best describes the result of running the program code?
(A) The number 0 is displayed.
(B) The number 6 is displayed.
(C) The number 10 is displayed.
(D) Nothing is displayed; the program results in an infinite loop.

AP Computer Science Principles Page 23 of 48


Scoring Guide

Term 1 - Mock 1

25. Consider the following code segment, where exam and presentation are integer variables and grade is
a string variable.

IF((exam > 90) AND (presentation > 80))


{
grade ← "A"
}
IF((exam > 80) OR (presentation > 75))
{
grade ← "B"
}
ELSE
{
IF((exam > 70) OR (presentation > 60))
{
grade ← "C"
}
ELSE
{
IF(exam > 60)
{
grade ← "D"
}
ELSE
{
grade ← "F"
}
}
}

Under which of the following conditions will the value "C" be assigned to the variable grade ?
(A) When the value of exam is 70 and the value of presentation is 50
(B) When the value of exam is 70 and the value of presentation is 80

(C) When the value of exam is 80 and the value of presentation is 60

(D) When the value of exam is 80 and the value of presentation is 80

Page 24 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

26. Consider the following program.

Which of the following describes the result of executing the program?


(A) The program displays the sum of the even integers from 2 to 10.
(B) The program displays the sum of the even integers from 2 to 20.
(C) The program displays the sum of the odd integers from 1 to 9.
(D) The program displays the sum of the odd integers from 1 to 19.

AP Computer Science Principles Page 25 of 48


Scoring Guide

Term 1 - Mock 1

27. A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the
number of elements in the list that have a value greater than 100. The algorithm uses the variables count and
position. Steps 3 and 4 are missing.

Step 1 Set count to 0 and position to 1.


Step 2 If the value of the element at index position is greater than 100, increase the value
of count by 1.
Step 3 (missing step)
Step 4 (missing step)
Step 5 Display the value of count.

Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended?

Step 3
Increase the value of position by 1.
(A)
Step 4
Repeat steps 2 and 3 until the value of count is greater than 100.

Step 3
Increase the value of position by 1.
(B)
Step 4
Repeat steps 2 and 3 until the value of position is greater than n.

Step 3
Repeat step 2 until the value of count is greater than 100.
(C)
Step 4
Increase the value of position by 1.

Step 3
Repeat step 2 until the value of position is greater than n.
(D)
Step 4
Increase the value of count by 1.

Page 26 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

28. 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)

29. A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display true
if the value target appears in the list more than once and to display false otherwise. The algorithm uses the
variables position and count. Steps 4 and 5 are missing.

Step 1: Set count to 0 and position to 1.


Step 2: If the value of the element at index position is equal to target, increase the
value of count by 1.
Step 3: Increase the value of position by 1.
Step 4: (missing step)
Step 5: (missing step)

Which of the following could be used to replace steps 4 and 5 so that the algorithm works as intended?

AP Computer Science Principles Page 27 of 48


Scoring Guide

Term 1 - Mock 1

Step 4
Repeat steps 2 and 3 until the value of position is greater than n.

(A) Step 5
If count is greater than or equal to 2, display true. Otherwise, display

false.

Step 4
Repeat steps 2 and 3 until the value of position is greater than n.

(B) Step 5
If count is greater than or equal to position, display true.

Otherwise, display false.

Step 4
Repeat steps 2 and 3 until the value of count is greater than 2.

(C) Step 5
If position is greater than or equal to n, display true. Otherwise,

display false.

Step 4
Repeat steps 2 and 3 until the value of count is greater than n.

(D) Step 5
If count is greater than or equal to 2, display true. Otherwise, display

false.

30. Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit
integer (i.e., in the range from 10 to 99, inclusive)?

Page 28 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(A) n = (n MOD 100)


(B) (n ≥ 10) AND (n < 100)
(C) (n < 10) AND (n ≥ 100)
(D) (n > 10) AND (n < 99)

A large spreadsheet contains the following information about local restaurants. A sample portion of the spreadsheet is
shown below.

C D E
A B
Number of Average Accepts
Restaurant Name Price Range
Customer Ratings Customer Rating Credit Cards
1 Joey Calzone’s Pizzeria lo 182 3.5 false
2 78th Street Bistro med 41 4.5 false
3 Seaside Taqueria med 214 4.5 true
4 Delicious Sub Shop II lo 202 4.0 false
5 Rustic Farm Tavern hi 116 4.5 true
6 ABC Downtown Diner med 0 -1.0 true

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.

31. 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?
(A) (avgRating ≥ 4.0) AND ((prcRange = "lo") AND (prcRange = "med"))

(B) (avgRating ≥ 4.0) AND ((prcRange = "lo") OR (prcRange = "med"))

(C) (avgRating ≥ 4.0) OR ((prcRange = "lo") AND (prcRange = "med"))


(D) (avgRating ≥ 4.0) OR ((prcRange = "lo") OR (prcRange = "med"))

32. To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must
have a science grade point average of over 3.2. Let overallGPA represent a student’s overall grade point
average and let scienceGPA represent the student’s science grade point average. Which of the following
expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?

AP Computer Science Principles Page 29 of 48


Scoring Guide

Term 1 - Mock 1

(A) (overallGPA > 3.0) AND (scienceGPA > 3.2)


(B) (overallGPA > 3.0) AND (scienceGPA ≥ 3.2)
(C) (overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
(D) (overallGPA ≥ 3.0) AND (scienceGPA ≥ 3.2)

33. A flowchart is a way to visually represent an algorithm. The flowchart below uses the following building blocks.

What is displayed as a result of executing the algorithm in the flowchart?

Page 30 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(A) 5
(B) 15
(C) 1 2 3 4
(D) 1 2 3 4 5

34. Consider the following code segment.

Which of the following replacements for <MISSING CONDITION> will result in an infinite loop?

(A) j = 6
(B) j ≥ 6
(C) j = 7
(D) j > 7

AP Computer Science Principles Page 31 of 48


Scoring Guide

Term 1 - Mock 1

35. The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single
output.

For which of the following input values will the circuit have an output of true ?
(A) A = true, B = true, C = true, D = false
(B) A = true, B = false, C = false, D = true

(C) A = false, B = true, C = true, D = true

(D) A = false, B = false, C = true, D = true

Page 32 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

36. The following grid contains a robot represented as a triangle, which is initially facing right.

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?

AP Computer Science Principles Page 33 of 48


Scoring Guide

Term 1 - Mock 1

(A) REPEAT 1 TIMES


(B) REPEAT 2 TIMES
(C) REPEAT 3 TIMES
(D) REPEAT 4 TIMES

37. A code segment is intended to transform the list utensils so that the last element of the list is moved to the
beginning of the list.

For example, if utensils initially contains ["fork", "spoon", "tongs", "spatula",


"whisk"], it should contain ["whisk", "fork", "spoon", "tongs", "spatula"] after
executing the code segment.

Which of the following code segments transforms the list as intended?


len LENGTH(utensils)
temp utensils[len]
(A) REMOVE(utensils, len)
APPEND(utensils, temp)
len LENGTH(utensils)
REMOVE(utensils, len)
(B) temp utensils[len]
APPEND(utensils, temp)
len LENGTH(utensils)
temp utensils[len]
(C) REMOVE(utensils, len)
INSERT(utensils, 1, temp)
len LENGTH(utensils)
REMOVE(utensils, len)
(D) temp utensils[len]
INSERT(utensils, 1, temp)

Page 34 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

38. The following grid contains a robot represented as a triangle. The robot is initially facing right.

Which of the following code segments can be used to move the robot to the gray square along the path indicated by
the arrows?

AP Computer Science Principles Page 35 of 48


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

Page 36 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(D)

39. 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.

Which of the following code segments can be used to move the robot to the gray square?

AP Computer Science Principles Page 37 of 48


Scoring Guide

Term 1 - Mock 1

REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 2 TIMES
{
(A) MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 8 TIMES
{
(B) MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 2 TIMES
{
(C) MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 2 TIMES
{
(D) MOVE_FORWARD()
}
ROTATE_RIGHT()
REPEAT 3 TIMES
{
MOVE_FORWARD()
}

Page 38 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

40. The grid below contains a robot represented as a triangle, 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.

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?
IF(CAN_MOVE(left))
{
(A) ROTATE_LEFT()
MOVE_FORWARD()
}
IF(CAN_MOVE(forward))
{
(B) MOVE_FORWARD()
ROTATE_LEFT()
}
IF(CAN_MOVE(left))
{
(C) ROTATE_LEFT()
}
MOVE_FORWARD()
IF(CAN_MOVE(forward))
{
MOVE_FORWARD()
}
(D) ELSE
{
ROTATE_LEFT()
}

AP Computer Science Principles Page 39 of 48


Scoring Guide

Term 1 - Mock 1

41. 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 gate is a type of logic gate that produces an output of only when both of its two inputs are
. Otherwise, the gate produces an output of . Which of the following Boolean expressions correctly
models a gate with inputs and ?

(A)

(B)

(C)

(D)

42. Three teams (Team A, Team B, and Team C) are participating in a trivia contest. Let scoreA represent the
number of correct questions for Team A, scoreB represent the number of correct questions for Team B, and
scoreC represent the number of correct questions for Team C. Assuming no two teams get the same number of
correct questions, which of the following code segments correctly displays the team with the highest number of
correct questions?

Page 40 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

AP Computer Science Principles Page 41 of 48


Scoring Guide

Term 1 - Mock 1

(D)

Page 42 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

43. A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score
greater than 90 is considered an A; a score between 80 and 90, inclusive, is considered a B; and any other score is
considered a C.

Which of the following code segments will assign the correct letter grade to grade based on the value of the
variable score ?

I.

AP Computer Science Principles Page 43 of 48


Scoring Guide

Term 1 - Mock 1

II.

Page 44 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

III.

(A) II only
(B) I and II only
(C) I and III only
(D) II and III only

44. In a certain country, a person must be at least 16 years old to drive a car and must be at least 18 years old to vote.
The variable age represents the age of a person as an integer.

Which of the following expressions evaluates to true if the person is old enough to drive but not old enough to
vote, and evaluates to false otherwise?

I. (age ≥ 16) AND (age ≤ 18)


II. (age ≥ 16) AND (NOT(age ≥ 18))
III. (age < 18) AND (NOT(age < 16))
(A) II only
(B) I and II only
(C) I and III only
(D) II and III only

AP Computer Science Principles Page 45 of 48


Scoring Guide

Term 1 - Mock 1

45. Consider the following procedures.

PROCEDURE proc1(str)
{
DISPLAY(str)
DISPLAY("happy")
}
PROCEDURE proc2(str1, str2)
{
proc1(str2)
DISPLAY(str1)
}

What is displayed as a result of the procedure call proc2("birthday", "to you") ?


(A) birthday happy to you
(B) birthday happy birthday
(C) to you birthday happy
(D) to you happy birthday

Page 46 of 48 AP Computer Science Principles


Scoring Guide

Term 1 - Mock 1

46. The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the
bottom-left square of the grid and facing toward the top of the grid.

Code for the procedure Mystery is shown below. Assume that the parameter p has been assigned a positive integer
value (e.g., 1, 2, 3, …).

Which of the following shows a possible result of calling the procedure?

AP Computer Science Principles Page 47 of 48


Scoring Guide

Term 1 - Mock 1

(A)

(B)

(C)

(D)

Page 48 of 48 AP Computer Science Principles

You might also like