0% found this document useful (0 votes)
21 views65 pages

AP Computer Science Principles 2020 Practice Exam 1 MCQ 3

The 2020 AP Computer Science Principles Practice Exam is a 2-hour test consisting of 67 multiple-choice questions. It includes instructions for administering the exam, scoring guidelines, and reference materials for programming concepts. The exam format requires students to answer questions using provided answer sheets, with no penalties for incorrect answers.

Uploaded by

eerdogdu3131
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)
21 views65 pages

AP Computer Science Principles 2020 Practice Exam 1 MCQ 3

The 2020 AP Computer Science Principles Practice Exam is a 2-hour test consisting of 67 multiple-choice questions. It includes instructions for administering the exam, scoring guidelines, and reference materials for programming concepts. The exam format requires students to answer questions using provided answer sheets, with no penalties for incorrect answers.

Uploaded by

eerdogdu3131
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/ 65

Practice Exam

Exam Content and Format


The 2020 AP Computer Science Principles Practice Exam is 2 hours in length
and consists of 67 multiple-choice questions.

Administering the Practice Exam


This section contains instructions for administering the AP Computer Science
Principles Practice Exam. You may wish to use these instructions to create an
exam situation that resembles an actual administration. If so, read the indented,
boldface directions to the students; all other instructions are for administering
the exam and need not be read aloud. Before beginning testing, have all exam
materials ready for distribution. These include test booklets and answer sheets.
(Reminder: Final instructions for every AP Exam are published in the AP Exam
Instructions book.)
When you are ready to begin the exam, say:
You will be given 2 hours to answer 67 multiple-choice questions. Each
question has 4 answer choices.
• For question numbers 1 through 6 , mark only the single best answer to
each question.

• For the remaining questions, numbered 131 through 137, mark the two
best answer choices for each question.

Your total score on this multiple-choice exam is based only on the number of
questions answered correctly. Points are not deducted for incorrect answers or
unanswered questions. When you do not know the answer to a question, you
should eliminate as many choices as you can, and then select the best answer
among the remaining choices. If you finish before time is called, you may
check your work.

Programming reference materials are located at the front of the exam.


The reference materials provide instructions and explanations to help you
understand the format and meaning of the questions on the test. As you
encounter programming questions on the test, you should use the reference
materials to clarify the behavior of programming statements found in those
questions.

You have 2 hours for this exam. Open your exam booklet and begin

Note Start Time here______ . Note Stop Time here______ . A"er 2 hours, say:

Stop working. The exam is over. I will now collect your exam materials.

Collect an exam booklet and answer sheet from each student.

4 AP Computer Science Principles Practice Exam


Name:

AP® Computer Science Principles


Answer Sheet

No. Answer No. Answer No. Answer


1 30 59
2 31 60
3 32
4 33
5 34
6 35
7 36
8 37
9 38
10 39 131
11 40 132
12 41 133
13 42 134
14 43 135
15 44 136
16 45 137
17 46
18 47
19 48
20 49
21 50
22 51
23 52
24 53
25 54
26 55
27 56
28 57
29 58

AP Computer Science Principles Practice Exam 5


AP Computer Science Principles Exam
®

Multiple Choice

DO NOT OPEN THIS BOOKLET UNTIL YOU ARE TOLD TO DO SO.

At a Glance Instructions
This exam booklet contains 67 multiple-choice questions. Exam reference materials for
Total Time programming questions are located at the beginning of this booklet. As you encounter
2 hours programming questions on the exam, you should use the reference materials to clarify the
Number of Questions behavior of programming statements found in those questions.
67
Percent of Total Score Indicate all of your answers to the multiple-choice questions on the answer sheet. No
60% credit will be given for anything written in this exam booklet, but you may use the booklet
Writing Instrument for notes or scratch work.
Pencil required
Electronic Device For questions 1 through 6 , select the single best answer choice for each question.
None allowed
For questions 131 through 137, select the two best answer choices for each question.
Use your time effectively, working as quickly as you can without losing accuracy. Do not
spend too much time on any one question. Go on to other questions and come back to
the ones you have not answered if you have time. It is not expected that everyone will
know the answers to all of the multiple-choice questions.
Your total score on the multiple-choice questions is based only on the number of
questions answered correctly. Points are not deducted for incorrect answers or unanswered
questions.

6 AP Computer Science Principles Practice Exam


COMPUTER SCIENCE PRINCIPLES
Time — 2 hours
67 Questions

Programming reference materials are included on the following pages. As AP Computer Science Principles does not
designate any particular programming language, these reference materials provide instructions and explanations to help
you understand the format and meaning of the questions you will see on the exam. The reference materials include two
programming formats, text-based and block-based.
Programming instructions use four data types: numbers, Booleans, strings, and lists.
Instructions from any of the following categories may appear on the exam:
• Assignment, Display, and Input
• Arithmetic Operators and Numeric Procedures
• Relational and Boolean Operators
• Selection
• Iteration
• List Operations
• Procedures
• Robot

AP Computer Science Principles Practice Exam 7


REFERENCE MATERIALS

Instruction Explanation
Assignment, Display, and Input
Text: Evaluates expression and assigns the result to
a ← expression the variable a.
Block:

Text: Displays the value of expression, followed by


DISPLAY (expression) a space.
Block:

Text: Accepts a value from the user and returns it.


INPUT ()
Block:

Arithmetic Operators and Numeric Procedures


Text and Block: The arithmetic operators +, -, *, and / are
a + b used to perform arithmetic on a and b.
a - b
a * b For example, 3 / 2 evaluates to 1.5.
a / b
Text and Block: Evaluates to the remainder when a is divided
a MOD b by b. Assume that a and b are positive
integers.
For example, 17 MOD 5 evaluates to 2.
Text: Evaluates to a random integer from a to b,
RANDOM (a, b) including a and b.
Block: For example, RANDOM (1, 3) could evaluate
to 1, 2, or 3.
Relational and Boolean Operators
Text and Block: The relational operators =, π , >, <,  , and 
a = b are used to test the relationship between two
a π b variables, expressions, or values.
a > b
a < b For example, a = b evaluates to true if a
a  b and b are equal; otherwise it evaluates to
a  b false.
Text: Evaluates to true if condition is false;
NOT condition otherwise evaluates to false.
Block:

Text: Evaluates to true if both condition1 and


condition1 AND condition2 condition2 are true; otherwise evaluates to
false.
Block:

8 AP Computer Science Principles Practice Exam


REFERENCE MATERIALS

Instruction Explanation
Relational and Boolean Operators (continued)
Text: Evaluates to true if condition1 is true
condition1 OR condition2 or if condition2 is true or if both
condition1 and condition2 are true;
Block:
otherwise evaluates to false.

Selection
Text: The code in block of statements is
IF (condition) executed if the Boolean expression condition
{ evaluates to true; no action is taken if
<block of statements> condition evaluates to false.
}
Block:

Text: The code in first block of statements


IF (condition) is executed if the Boolean expression
{ condition evaluates to true; otherwise the
<first block of statements> code in second block of statements is
} executed.
ELSE
{
<second block of statements>
}
Block:

Iteration
Text: The code in block of statements is
REPEAT n TIMES executed n times.
{
<block of statements>
}
Block:

AP Computer Science Principles Practice Exam


REFERENCE MATERIALS
Instruction Explanation
Iteration (continued)
Text: The code in block of statements is
REPEAT UNTIL (condition) repeated until the Boolean expression
{ condition evaluates to true.
<block of statements>
}
Block:

List Operations
For all list operations, if a list index is less than 1 or greater than the length of the list, an error message
is produced and the program terminates.
Text: Refers to the element of list at index i. The
list[i] first element of list is at index 1.
Block:

Text: Assigns the value of list[j] to list[i].


list[i] ← list[j]
Block:

Text: Assigns value1, value2, and value3 to


list ← [value1, value2, value3] list[1], list[2], and list[3],
respectively.
Block:

Text: The variable item is assigned the value of each


FOR EACH item IN list element of list sequentially, in order from the
{ first element to the last element. The code in
<block of statements> block of statements is executed once for
} each assignment of item.
Block:

AP Computer Science Principles Practice Exam


REFERENCE MATERIALS
Instruction Explanation
List Operations (continued)
Text: Any values in list at indices greater than or
INSERT (list, i, value) equal to i are shifted to the right. The length of
list is increased by 1, and value is placed at
Block:
index i in list.

Text: The length of list is increased by 1, and


APPEND (list, value) value is placed at the end of list.
Block:

Text: Removes the item at index i in list and shifts


REMOVE (list, i) to the left any values at indices greater than i. The
length of list is decreased by 1.
Block:

Text: Evaluates to the number of elements in list.


LENGTH (list)
Block:

Procedures
Text: A procedure, name, takes zero or more
PROCEDURE name (parameter1, parameters. The procedure contains programming
parameter2, ...) instructions.
{
<instructions>
}
Block:

Text: A procedure, name, takes zero or more


PROCEDURE name (parameter1, parameters. The procedure contains programming
parameter2, ...) instructions and returns the value of
{ expression. The RETURN statement may
<instructions> appear at any point inside the procedure and causes
RETURN (expression) an immediate return from the procedure back to the
} calling program.

Block:

AP Computer Science Principles Practice Exam


REFERENCE MATERIALS

Instruction Explanation
Robot
If the robot attempts to move to a square that is not open or is beyond the edge of the grid, the robot will
stay in its current location and the program will terminate.
Text: The robot moves one square forward in the
MOVE_FORWARD () direction it is facing.
Block:

Text: The robot rotates in place 90 degrees


ROTATE_LEFT () counterclockwise (i.e., makes an in-place left turn).
Block:

Text: The robot rotates in place 90 degrees clockwise


ROTATE_RIGHT () (i.e., makes an in-place right turn).
Block:

Text: Evaluates to true if there is an open square one


CAN_MOVE (direction) square in the direction relative to where the robot is
facing; otherwise evaluates to false. The value
Block:
of direction can be left, right, forward, or
backward.

AP Computer Science Principles Practice Exam


Directions: Each of the questions or incomplete statements below is followed by four suggested answers or
completions. Select the one that is best in each case and then in the corresponding on the
answer sheet.

1. Consider the following program.

Which of the following expressions represents the value stored in the variable x as a result of executing the
program?
(A) 2 * 3 * 3 * 3
(B) 2 * 4 * 4 * 4
(C) 2 * 3 * 3 * 3 * 3
(D) 2 * 4 * 4 * 4 * 4

2. A small team of wildlife researchers is working on a project that uses motion-activated field cameras to capture
images of animals at study sites. The team is considering using a “citizen science” approach to analyze the
images. Which of the following best explains why such an approach is considered useful for this project?
(A) Distributed individuals are likely to be more accurate in wildlife identification than the research team.
(B) The image analysis is likely to be more consistent if completed by an individual citizen.
(C) The image analysis is likely to require complex research methods.
(D) The image analysis is likely to take a longer time for the research team than for a distributed group of
individuals.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 13


. An algorithm is intended to display the following output.
red red blue red red blue red red blue
Which of the following code segments can be used to display the intended output?

(A) (B)

(C) (D)

GO ON TO THE NEXT PAGE.

14 AP Computer Science Principles Practice Exam


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.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 15


. 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

GO ON TO THE NEXT PAGE.

16 AP Computer Science Principles Practice Exam


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

The following programs are each intended to move the robot to the gray square. Program II uses the
procedure GoalReached, which returns true if the robot is in the gray square and returns false
otherwise.

Which of the following statements best describes the correctness of the programs?
(A) Program I correctly moves the robot to the gray square, but program II does not.
(B) Program II correctly moves the robot to the gray square, but program I does not.
(C) Both program I and program II correctly move the robot to the gray square.
(D) Neither program I nor program II correctly moves the robot to the gray square.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 17


7 Flight simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of
the following is LEAST likely to be an advantage of using flight simulation software for this purpose?
(A) Flight simulation software allows pilots to practice landing in a variety of different terrains and weather
conditions without having to physically travel.
(B) Flight simulation software could save money due to the cost of maintenance and fuel for actual training
flights.
(C) Flight simulation software provides a more realistic experience for pilots than actual training flights.
(D) Flight simulation software allows for the testing of emergency air situations without serious consequences.

Which of the following actions are generally helpful in program development?


Consulting potential users of the program to identify their concerns
Writing and testing small code segments before adding them to the program
Collaborating with other individuals when developing a large program
A) I and II only
B) I and III only
C) II and III only
D) I, II, and III

GO ON TO THE NEXT PAGE.

18 AP Computer Science Principles Practice Exam


An Internet user has a need to send private data to another user. Which of the following provides the most
security when transmitting private data?
(A) Certifying the data with a Creative Commons license before sending it
(B) Sending the data using a high-bandwidth connection
(C) Sending the data using public-key encryption
(D) Sending the data using redundant routing

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 19


. Ticket prices for a science museum are shown in the following table.

Type of Ticket General Admission Cost Guided Tour Cost


(in dollars) (in dollars)
Regular (ages 13 and up) 8 10
Child (ages 12 and below) 6 8
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?

(A) cost ← 6 (B) cost ← 6


IF ((age > 12) OR includesTour) IF (age > 12)
{ {
cost ← cost + 2 cost ← cost + 2
} }
DISPLAY (cost) IF (includesTour)
{
cost ← cost + 2
}
DISPLAY (cost)

(C) cost ← 6 (D) cost ← 6


IF (age > 12) IF (age > 12)
{ {
IF (includesTour) cost ← cost + 2
{ }
cost ← cost + 2 ELSE
} {
} IF (includesTour)
DISPLAY (cost) {
cost ← cost + 2
}
}
DISPLAY (cost)

GO ON TO THE NEXT PAGE.

20 AP Computer Science Principles Practice Exam


Questions – refer to the information below.
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).
Color Name RGB Triplet
indigo (75, 0, 130)
ivory (255, 255, 240)
light pink (255, 182, 193)
light yellow (255, 255, 224)
magenta (255, 0, 255)
neutral gray (127, 127, 112)
pale yellow (255, 255, 160)
vivid yellow (255, 255, 14)

According to information in the table, what color is represented by the binary RGB
triplet (11111111, 11111111, 11110000) ?

(A) Ivory
(B) Light yellow
(C) Neutral gray
(D) Vivid yellow

What is the binary RGB triplet for the color indigo?


(A) (00100101, 00000000, 10000010)
(B) (00100101, 00000000, 01000001)
(C) (01001011, 00000000, 10000010)
(D) (01001011, 00000000, 01000001)

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 21


A library system contains information for each book that was borrowed. Each time a person borrows or returns a
book from the library, the following information is recorded in a database.
• Name and the unique ID number of the person who was borrowing the book
• Author, title, and the unique ID number of the book that was borrowed
• Date that the book was borrowed
• Date that the book was due to be returned
• Date that the book was returned (or 0 if the book has not been returned yet)
Which of the following CANNOT be determined from the information collected by the system?

(A) The total number of books borrowed in a given year


(B) The total number of books that were never borrowed in a given year
(C) The total number of books that were returned past their due date in a given year
(D) The total number of people who borrowed at least one book in a given year

GO ON TO THE NEXT PAGE.

22 AP Computer Science Principles Practice Exam


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

(A) Step 3: Display the remainder of number divided by 10 and store the remainder in number.
(B) Step 3: Display the remainder of number divided by 10 and store the integer quotient in number.
(C) Step 3: Display the integer quotient of number divided by 10 and store the remainder in number.
(D) Step 3: Display the integer quotient of number divided by 10 and store the integer quotient
in number.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 23


. Consider the two programs below.

Which of the following best compares the values displayed by programs A and B?

(A) Program A and program B display identical values in the same order.
(B) Program A and program B display the same values in different orders.
(C) Program A and program B display the same number of values, but the values differ.
(D) Program B displays one more value than program A.

GO ON TO THE NEXT PAGE.

24 AP Computer Science Principles Practice Exam


6. A student wrote the following program to remove all occurrences of the strings "the" and "a" from the
list wordList.
Line 1: index ← LENGTH (wordList)
Line 2: REPEAT UNTIL (index < 1)
Line 3: {
Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a"))
Line 5: {
Line 6: REMOVE (wordList, index)
Line 7: }
Line 8: }
While debugging the program, the student realizes that the loop never terminates. Which of the following
changes can be made so that the program works as intended?
(A) Inserting index ← index + 1 between lines 6 and 7
(B) Inserting index ← index + 1 between lines 7 and 8
(C) Inserting index ← index - 1 between lines 6 and 7
(D) Inserting index ← index - 1 between lines 7 and 8

7 Which of the following can be represented by a sequence of bits?


An integer
An alphanumeric character
A machine language instruction
A) I only
B) III only
C) I and II only
D) I, II, and III

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 25


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

GO ON TO THE NEXT PAGE.

26 AP Computer Science Principles Practice Exam


NO TEST MATERIAL ON THIS PAGE

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 27


Questions – refer to the information below.
A file storage application allows users to save their files on cloud servers. A group of researchers gathered user data for
the first eight years of the application’s existence. Some of the data are summarized in the following graphs. The line
graph on the left shows the number of registered users each year. The line graph on the right shows the total amount of
data stored by all users each year. The circle graph shows the distribution of file sizes currently stored by all users.

(note: 1 MB ! 1,000 KB)

GO ON TO THE NEXT PAGE.

28 AP Computer Science Principles Practice Exam


Which of the following best describes the growth in the number of registered users for the first eight years of the
application’s existence?
(A) The number of registered users increased at about a constant rate each year for all eight years.
(B) The number of registered users increased at about a constant rate for years 1 to 5 and then about doubled
each year after that.
(C) The number of registered users about doubled each year for years 1 to 5 and then increased at about a
constant rate after that.
(D) The number of registered users about doubled each year for all eight years.

Which of the following best describes the average amount of data stored per user for the first eight years of the
application’s existence?
(A) Across all eight years, the average amount of data stored per user was about 10 GB.
(B) Across all eight years, the average amount of data stored per user was about 100 GB.
(C) The average amount of data stored per user appears to increase by about 10 GB each year.
(D) The average amount of data stored per user appears to increase by about 100 GB each year.

Which of the following observations is most consistent with the information in the circle graph?
(A) Over 75% of the files stored are 1 MB in size or less.
(B) Over 75% of the files stored are 10 MB in size or less.
(C) Over 75% of the files stored are at least 100 KB in size.
(D) Over 75% of the files stored are at least 1 MB in size.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 29


. Consider the following spinner, which is used to determine how pieces are to be moved on a game board. The
region labeled "Move 1 space" is six times as large as each of the other two regions.

Which of the following code segments can be used to simulate the behavior of the spinner?
(A)

(B)

GO ON TO THE NEXT PAGE.

30 AP Computer Science Principles Practice Exam


(C)

(D)

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 31


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

Block Explanation
Oval The start or end of the algorithm
Diamond A conditional or decision step, where execution
proceeds to the side labeled true if the
condition is true and to the side labeled false
otherwise
Rectangle One or more processing steps, such as a
statement that assigns a value to a variable

GO ON TO THE NEXT PAGE.

32 AP Computer Science Principles Practice Exam


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

(A)

(B)

(C)

(D)

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 33


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

GO ON TO THE NEXT PAGE.

34 AP Computer Science Principles Practice Exam


Which of the following statements correctly explain how the Internet is able to facilitate communication at a
large scale?
A central monitoring computer is used to track and maintain the connections of the Internet.
Data is routed between points in multiple ways so that if a connection fails, the data can be rerouted
around the inoperative connections.
Protocols for packets and routing are used so that computers from different manufacturers can
communicate in a standard way.
A) I and II only
B) I and III only
C) II and III only
D) I, II, and III

6 A list of binary values (0 or 1) is used to represent a black-and-white image. Which of the following is LEAST
likely to be stored as metadata associated with the image?
(A) Copyright information for the image
(B) The date and time the image was created
(C) The dimensions (number of rows and columns of pixels) of the image
(D) A duplicate copy of the data

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 35


7 Which of the following best explains why it is not possible to use computers to solve every problem?
(A) Current computer processing capabilities cannot improve significantly.
(B) Large-scale problems require a crowdsourcing model, which is limited by the number of people
available to work on the problem.

(C) The ability of a computer to solve a problem is limited by the bandwidth of the computer’s Internet
connection.
(D) There exist some problems that cannot be solved using any algorithm.

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

II.

III.

(A) I and II only


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

GO ON TO THE NEXT PAGE.

36 AP Computer Science Principles Practice Exam


A person wants to transmit an audio file from a device to a second device. Which of the following scenarios best
demonstrates the use of lossless compression of the original file?
(A) A device compresses the audio file before transmitting it to a second device. The second device restores
the compressed file to its original version before playing it.
(B) A device compresses the audio file by removing details that are not easily perceived by the human ear. The
compressed file is transmitted to a second device, which plays it.
(C) A device transmits the original audio file to a second device. The second device removes metadata from
the file before playing it.
(D) A device transmits the original audio file to a second device. The second device plays the transmitted file
as is.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 37


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


(A) too high
(B) in range
(C) too low
(D) out of range

GO ON TO THE NEXT PAGE.

38 AP Computer Science Principles Practice Exam


A student purchases a single-user license of a copyrighted application and wants other students to be able to use
it at the same time. Under which of the following conditions is it considered acceptable for the student to share the
application?

(A) When the application is shared only with students at the same school
(B) When the application is shared on a peer-to-peer network
(C) When the student gets permission from the copyright owner of the application
(D) When the student makes a copy of the application for another student to use only once

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 39


Questions – refer to the information below.
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) /90 3.

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

GO ON TO THE NEXT PAGE.

40 AP Computer Science Principles Practice Exam


An administrator at the school has data about hundreds of students in a particular course. While the
administrator does not know the values of each student’s individual assignment scores, the administrator does have
the following information for each student.
• The student name
• A unique student ID number
• The number of assignments for the course
• The average assignment score before the lowest score was dropped
• The course grade after the lowest score was dropped
Which of the following CANNOT be determined from this data alone?

(A) For a given student, the value of the highest assignment score
(B) For a given student, the value of the lowest assignment score
(C) For a given student, the change in course grade as a result of dropping the lowest score
(D) The proportion of students who improved their course grade as a result of dropping the lowest score

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 41


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

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

(C) (D)

GO ON TO THE NEXT PAGE.

42 AP Computer Science Principles Practice Exam


A programmer notices the following two procedures in a library. The procedures do similar, but not identical,
things.
• Procedure MaxTwo (x, y) returns the greater of its two integer parameters.
• Procedure MaxThree (x, y, z) returns the greatest of its three integer parameters.
Which of the following procedures is a generalization of the MaxTwo and MaxThree procedures?

(A) Procedure Min (x, y), which returns the lesser of its two integer parameters
(B) Procedure Max (numList), which returns the maximum value in the list of integers numList
(C) Procedure MaxFour (w, x, y, z), which returns the greatest of its four integer parameters
(D) Procedure OverMax (numList, max), which returns the number of integers in numList that
exceed the integer value max

6 A group of planners are using a simulation to examine whether or not a park that they are designing is going to
affect foot traffic in the area. The simulation uses a model that includes input variables for the park such as the
number of entrances, sidewalks, and bike trails and the square footage of open space (grassy areas). The simulation
can then be run multiple times using different values for the input variables to represent different park designs.
However, the simulation takes a very long time to run. The planners update the model by removing some variables
they consider less important than others. Of the following, which is the most likely effect the updated model will
have on the simulation?

(A) The updated model is likely to decrease the runtime of the simulation because the time required for
simulations generally depends on the complexity of the model used.
(B) The updated model is likely to decrease the runtime of the simulation because simulations that use older
models tend to require more time to run than simulations that use newer models.
(C) The updated model is unlikely to decrease the runtime of the simulation because the simulation is
computationally complex, regardless of the model used.
(D) The updated model is unlikely to provide any benefit because removing details from a model will
compromise the accuracy of the simulation.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 43


7. Consider the following procedure.

Procedure Call Explanation


DrawLine (x1, y1, x2, y2) Draws a line segment on a coordinate grid with endpoints at
coordinates (x1, y1) and (x2, y2)
The DrawLine procedure is to be used to draw the following figure on a coordinate grid.

The following code segment is intended to draw the figure.


startX ← 2
startY ← 6
endX ← 8
endY ← 8
REPEAT 4 TIMES
{
<MISSING CODE>
}
Which of the following can be used to replace <MISSING CODE> so that the figure is drawn correctly?

(A) DrawLine (startX, startY, endX, endY)


endY ← endY - 2
(B) DrawLine (startX, startY, endX, endY)
endX ← endX - 2
endY ← endY - 2
(C) endY ← endY - 2
DrawLine (startX, startY, endX, endY)

(D) endX ← endX - 2


endY ← endY - 2
DrawLine (startX, startY, endX, endY)

GO ON TO THE NEXT PAGE.

44 AP Computer Science Principles Practice Exam


Internet protocol version 6 (IPv6) has been introduced to replace the previous version (IPv4). Which of the
following best describes a benefit of IPv6 over IPv4 ?
(A) IPv6 addresses are shorter than IPv4 addresses, which allows for faster routing of packets.
(B) IPv6 allows for a greater number of addresses than IPv4, which allows more devices to be connected to
the Internet.
(C) IPv6 eliminates the use of hierarchy in addressing, making addresses easier to use.
(D) IPv6 allows users to bypass older security protocols so that data can be sent peer-to-peer without the use of
routers.

. Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute
and display the sum of the first 10 elements of nums.
Line 1: i ← 1
Line 2: sum ← 0
Line 3: REPEAT UNTIL (i > 10)
Line 4: {
Line 5: i ← i + 1
Line 6: sum ← sum + nums[i]
Line 7: }
Line 8: DISPLAY (sum)
Which change, if any, is needed for the program to work as intended?
(A) Lines 1 and 2 should be interchanged.
(B) Line 3 should be changed to REPEAT UNTIL (i ≥ 10).
(C) Lines 5 and 6 should be interchanged.
(D) No change is needed; the program works correctly.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 45


Which of the following best explains how a certificate authority is used in protecting data?
(A) A certificate authority certifies the safety of a particular Web site so that users know that it does not
contain any viruses.
(B) A certificate authority issues passwords that grant access to secure databases.
(C) A certificate authority maintains a secure database that maps all Web domain names to the IP addresses of
the servers where the sites are hosted.
(D) A certificate authority verifies the authenticity of encryption keys used in secured communications.

GO ON TO THE NEXT PAGE.

46 AP Computer Science Principles Practice Exam


. A photographer has a collection of digital pictures, each using the same file-naming format: a date tag, followed
by a description, followed by the file extension ".jpg". The photographer wants to write a code segment to
extract the description from each file name, as shown in the following table.

Original File Name Extracted Description


2016-05-22-Andrews-Graduation.jpg Andrews-Graduation
2016-07-04-Fireworks.jpg Fireworks
2017-10-18-Grandmas-Birthday.jpg Grandmas-Birthday
The photographer has the following procedures available.

Procedure Call Explanation


TrimLeft (str, n) Returns a copy of the string str with the n
leftmost characters removed. For example,
TrimLeft ("keyboard", 3) returns
"board".
TrimRight (str, n) Returns a copy of the string str with the n
rightmost characters removed. For example,
TrimRight ("keyboard", 3) returns
"keybo".
Let an original file name be stored in the string variable original. Which of the following statements will
correctly extract the description and store it in the string variable descr ?
I. descr ← TrimLeft (TrimRight (original, 4), 11)
II. descr ← TrimLeft (TrimRight (original, 11), 4)
III. descr ← TrimRight (TrimLeft (original, 11), 4)

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

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 47


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)

GO ON TO THE NEXT PAGE.

48 AP Computer Science Principles Practice Exam


Questions – refer to the information below.
The figure below shows two possible network configurations for devices P through V. A line between two devices
indicates a connection. Devices can communicate only through the connections shown.

In which of the configurations is it possible to have redundant routing between devices Q and V?
(A) Configuration I only
(B) Configuration II only
(C) Both configuration I and configuration II
(D) Neither configuration I nor configuration II

In configuration I, what is the minimum number of connections that must be broken or removed before device T
can no longer communicate with device U?
(A) One
(B) Two
(C) Three
(D) Four

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 49


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

(A) (B)

(C) (D)

GO ON TO THE NEXT PAGE.

50 AP Computer Science Principles Practice Exam


6 Which of the following best explains how IP addresses are assigned?
(A) As a new device is connected to the Internet, it is assigned an IP address to enable communication on
the network.
(B) IP addresses are assigned only to servers that host Web sites; user devices do not require an IP address.
(C) New devices are connected to the Internet without an IP address, but are eventually assigned an IP address
once they can be verified by a certificate authority.
(D) New devices are connected to the Internet without an IP address; IP addresses are assigned only for
encrypted communications.

7 The procedure BinarySearch (numList, target) correctly implements a binary search algorithm
on the list of numbers numList. The procedure returns an index where target occurs in numList, or -1 if
target does not occur in numList. Which of the following conditions must be met in order for the procedure
to work as intended?
(A) The length of numList must be even.
(B) The list numList must not contain any duplicate values.
(C) The values in numList must be in sorted order.
(D) The value of target must not be equal to -1.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 51


Which of the following scenarios best exemplifies a phishing attack?
(A) A user connects to a public wireless network. An unauthorized individual intercepts data transmitted on
the network, looking for private information that can be used to gain access to the user’s accounts.
(B) A user’s e-mail account is overwhelmed with messages containing large attachments, which causes the
account to exceed the maximum amount of data allowed and temporarily prevents the user from sending
and receiving new messages.
(C) A user receives an e-mail from a sender offering technical help with the user’s computer. The e-mail
prompts the user to start a help session by clicking a provided link and entering the username and
password associated with the user’s computer.
(D) A user chooses a weak password for an online account. An unauthorized individual successfully guesses
the user’s password from a list of common passwords.

An office uses an application to assign work to its staff members. The application uses a binary sequence to
represent each of 100 staff members. What is the minimum number of bits needed to assign a unique bit
sequence to each staff member?
(A) 5
(B) 6
(C) 7
(D) 8

GO ON TO THE NEXT PAGE.

52 AP Computer Science Principles Practice Exam


Consider the following algorithms. Each algorithm operates on a list containing n elements, where n is a very
large integer.
An algorithm that accesses each element in the list twice
An algorithm that accesses each element in the list n times
An algorithm that accesses only the first 10 elements in the list, regardless of the size of the list
Which of the algorithms run in reasonable time?
(A) I only
(B) III only
(C) I and II only
(D) I, II, and III

Which of the following best describes the impact of Creative Commons?


(A) Creative Commons gives creators of digital content the ability to indicate how their works can be
legally used and distributed, enabling broad access to digital information.
(B) Creative Commons gives Internet users the right to legally use and distribute any previously copyrighted
work, enabling broad access to digital information.
(C) Create Commons provides lossless transmission of messages, enabling reliable distribution of digital
information.
(D) Creative Commons provides private transmission of messages, enabling secure distribution of digital
information.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 53


. A biologist wrote a program to simulate the population of a sample of bacteria. The program uses the following
procedures.

Procedure Call Explanation


InitialPopulation () Returns the number of bacteria at the start of the
simulation
NextPopulation (currPop) Based on the current value of currPop, returns
the number of bacteria after one hour
Code for the simulation is shown below.
hours ← 0
startPop ← InitialPopulation ()
currentPop ← startPop
REPEAT UNTIL ((hours ≥ 24) OR (currentPop ≤ 0))
{
currentPop ← NextPopulation (currentPop)
hours ← hours + 1
}
DISPLAY (currentPop - startPop)
Which of the following are true statements about the simulation?
I. The simulation continues until either 24 hours pass or the population reaches 0.
II. The simulation displays the average change in population per hour over the course of the simulation.
III. The simulation displays the total population at the end of the simulation.

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

GO ON TO THE NEXT PAGE.

54 AP Computer Science Principles Practice Exam


A system is being developed to help pet owners locate lost pets. Which of the following best describes a system
that uses crowdsourcing?
(A) A mobile application and collar that uses GPS technology to determine the pet’s location and transmits the
location when the owner refreshes the application
(B) A mobile application and collar that uses wireless technology to determine whether the pet is within 100
feet of the owner’s phone and transmits a message to the owner when the pet is nearby
(C) A mobile application that allows users to report the location of a pet that appears to be lost and upload a
photo that is made available to other users of the application
(D) A mobile application that transmits a message to all users any time a lost pet is returned to its owner

. Assume that the list originalList contains integer values and that the list newList is initially empty.
The following code segment is intended to copy all even numbers from originalList to newList so that
the numbers in newList appear in the same relative order as in originalList. The code segment may
or may not work as intended.
Line 1: FOR EACH number IN originalList
Line 2: {
Line 3: IF (number MOD 2 = 0)
Line 4: {
Line 5: INSERT (newList, 1, number)
Line 6: }
Line 7: }
Which of the following changes, if any, can be made so that the code segment works as intended?
(A) Changing line 1 to FOR EACH number IN newList
(B) Changing line 3 to IF (number MOD 2 = 1)
(C) Changing line 5 to APPEND (newList, number)
(D) No change is needed; the code segment is correct as is.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 55


. The following algorithm is intended to determine the average height, in centimeters, of a group of people in a
room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing.
Step 1: All people stand up.

Step 2: (missing step)

Step 3: Each standing person finds another standing person and they form a pair. If a person
cannot find an unpaired standing person, that person remains standing and waits
until the next opportunity to form pairs.

Step 4: In each pair, one person hands their card to the other person and sits down.

Step 5: At this point, the standing person in each pair is holding two cards. The standing
person in each pair replaces the top number on their card with the sum of the top
numbers on the two cards and replaces the bottom number on their card with the
sum of the bottom numbers on the two cards. The sitting partner’s card is discarded.

Step 6: Repeat steps 3–5 until there is only one person standing.

Step 7: The last person standing divides the top number by the bottom number to determine
the average height.

Which of the following can be used as step 2 so that the algorithm works as intended?
(A) Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 1 at
the bottom of the card.
(B) Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 2 at
the bottom of the card.
(C) Step 2: Each person writes the number 1 at the top of the card and writes their height, in centimeters, at
the bottom of the card.
(D) Step 2: Each person writes the number 2 at the top of the card and writes their height, in centimeters, at
the bottom of the card.

GO ON TO THE NEXT PAGE.

56 AP Computer Science Principles Practice Exam


6. An online game collects data about each player’s performance in the game. A program is used to analyze the
data to make predictions about how players will perform in a new version of the game.
The procedure GetPrediction (idNum) returns a predicted score for the player with ID
number idNum. Assume that all predicted scores are positive. The GetPrediction procedure takes
approximately 1 minute to return a result. All other operations happen nearly instantaneously.
Two versions of the program are shown below.

Version I
topScore ← 0
idList ← [1298702, 1356846, 8848491, 8675309]
FOR EACH id IN idList
{
score ← GetPrediction (id)
IF (score > topScore)
{
topScore ← score
}
}
DISPLAY (topScore)
Version II
idList ← [1298702, 1356846, 8848491, 8675309]
topID ← idList[1]
FOR EACH id IN idList
{
IF (GetPrediction (id) > GetPrediction (topID))
{
topID ← id
}
}
DISPLAY (GetPrediction (topID))
Which of the following best compares the execution times of the two versions of the program?

(A) Version I requires approximately 1 more minute to execute than version II.
(B) Version I requires approximately 5 more minutes to execute than version II.
(C) Version II requires approximately 1 more minute to execute than version I.
(D) Version II requires approximately 5 more minutes to execute than version I.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 57


7 The transmission control protocol (TCP) and Internet protocol (IP) are used in Internet communication. Which
of the following best describes the purpose of these protocols?
(A) To ensure that communications between devices on the Internet are above a minimum transmission speed
(B) To ensure that private data is inaccessible to unauthorized devices on the Internet
(C) To establish a common standard for sending messages between devices on the Internet
(D) To validate the ownership of encryption keys used in Internet communication

. The following procedure is intended to return true if at least two of the three parameters are equal in value
and is intended to return false otherwise.
PROCEDURE AnyPairs (x, y, z)
{
IF (x = y)
{
RETURN (true)
}
ELSE
{
RETURN (y = z)
}
}
For which of the following procedure calls does the procedure NOT return the intended value?

(A) AnyPairs ("bat", "cat", "rat")


(B) AnyPairs ("bat", "bat", "rat")
(C) AnyPairs ("bat", "cat", "bat")
(D) AnyPairs ("bat", "cat", "cat")

GO ON TO THE NEXT PAGE.

58 AP Computer Science Principles Practice Exam


Which of the following is NOT an advantage of using open-source software?
(A) Open-source software is generally free or lower in cost than commercially available software.
(B) The availability of source code makes it possible to customize open-source software to a user’s
individual needs.
(C) The original developer of open-source software provides free or low-cost support for users installing and
running the software.
(D) Unlike commercial software, which can become obsolete when the company that created it goes out of
business, open-source software can be updated without the involvement of the original programmers.

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 59


6 . Consider two lists of numbers called list1 and list2. A programmer wants to determine how many
different values appear in both lists. For example, if list1 contains
[10, 10, 20, 30, 40, 50, 60] and list2 contains [20, 20, 40, 60, 80], then there are
three different values that appear in both lists (20, 40, and 60).
The programmer has the following procedures available.

Procedure Call Explanation


Combine (myList1, myList2) This procedure creates a new list containing the elements from
myList1 followed by the entries from myList2. The resulting
list is returned. For example, if myList1 contains [2, 4, 6] and
myList2 contains [1, 5], the procedure will return the list
[2, 4, 6, 1, 5].
RemoveAllDups (myList) This procedure creates a new list containing the elements of myList
with any duplicate values removed. The resulting list is returned. For
example, if myList contains [3, 2, 4, 2, 2, 5, 6, 4],
the procedure will return the list [3, 2, 4, 5, 6].
Which of the following can be used to assign the intended value to count ?
(A) bothList ← Combine (list1, list2)
uniqueList ← RemoveAllDups (bothList)
count ← LENGTH (bothList) - LENGTH (uniqueList)
(B) newList1 ← RemoveAllDups (list1)
newList2 ← RemoveAllDups (list2)
bothList ← Combine (newList1, newList2)
count ← LENGTH (list1) + LENGTH (list2) - LENGTH (bothList)
(C) newList1 ← RemoveAllDups (list1)
newList2 ← RemoveAllDups (list2)
bothList ← Combine (newList1, newList2)
count ← LENGTH (newList1) + LENGTH (newList2) - LENGTH (bothList)
(D) newList1 ← RemoveAllDups (list1)
newList2 ← RemoveAllDups (list2)
bothList ← Combine (newList1, newList2)
uniqueList ← RemoveAllDups (bothList)
count ← LENGTH (bothList) - LENGTH (uniqueList)

GO ON TO THE NEXT PAGE.

60 AP Computer Science Principles Practice Exam


Questions – 7

Directions: For each of the questions or incomplete statements below, two of the suggested answers are correct. For
each of these questions, 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 and then in the corresponding
that begin with number 131 on the answer sheet.

131. Which of the following actions are likely to be helpful in reducing the digital divide?

Select two answers.


(A) Designing new technologies intended only for advanced users
(B) Designing new technologies to be accessible to individuals with different physical abilities
(C) Implementing government regulations restricting citizens’ access to Web content
(D) Having world governments support the construction of network infrastructure

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 61


132. 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) (B)

(C) (D)

GO ON TO THE NEXT PAGE.

62 AP Computer Science Principles Practice Exam


133. A bookstore has a database containing information about each book for sale in the store. A sample portion of
the database is shown below.

Author Title Selling Price Genre Quantity Available


J. M. Barrie Peter and Wendy $6.99 Fantasy 3
L. Frank Baum The Wonderful Wizard of Oz $7.99 Fantasy 2
Arthur Conan Doyle The Hound of the Baskervilles $7.49 Mystery 4
Mary Shelley Frankenstein $7.99 Horror 4
Jules Verne Twenty Thousand Leagues Under the Sea $6.99 Science Fiction 3
H. G. Wells The War of the Worlds $4.99 Science Fiction 3
A store employee wants to calculate the total amount of money the store will receive if they sell all of the
available science fiction books. Which columns in the database can be ignored and still allow the employee to
perform this calculation?
Select two answers.
(A) Author
(B) Title
(C) Genre
(D) Quantity Available

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 63


134. 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?
Select two answers.

(A)

(B)

(C)

(D)

GO ON TO THE NEXT PAGE.

64 AP Computer Science Principles Practice Exam


135. A program contains the following procedures for string manipulation.

Procedure Call Explanation


Concat (str1, str2) Returns a single string consisting of str1 followed by str2. For
example, Concat ("key", "board") returns "keyboard".
Substring (str, start, length) Returns a substring of consecutive characters from str, starting with
the character at position start and containing length characters.
The first character of str is located at position 1. For example,
Substring ("delivery", 3, 4) returns "live".

Which of the following can be used to store the string "jackalope" in the string variable animal ?
Select 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)

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 65


NO TEST MATERIAL ON THIS PAGE

GO ON TO THE NEXT PAGE.

66 AP Computer Science Principles Practice Exam


6. 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.
(A) Line 5
(B) Line 8
(C) Line 9
(D) Line 11

GO ON TO THE NEXT PAGE.

AP Computer Science Principles Practice Exam 67


7. 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?
Select two answers.

(A)

(B)

(C)

(D)

STOP

IF YOU FINISH BEFORE TIME IS CALLED, YOU MAY


CHECK YOUR WORK ON THIS TEST.

68 AP Computer Science Principles Practice Exam

You might also like