AP CSP Exam Reference Sheet

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

AP ®

CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

AP Computer Science Principles Exam


Reference Sheet
As AP Computer Science Principles does not designate any particular programming
language, this reference sheet provides instructions and explanations to help
students understand the format and meaning of the questions they will see on
the exam. The reference sheet includes 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

© 2017 The College Board


118
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

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

Text: Displays the value of expression,


DISPLAY (expression) followed by 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
For example, 3 / 2 evaluates to 1.5.
a * b
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
For example, a = b evaluates to true if
a < b
a and b are equal; otherwise, it evaluates to
a ≥ b
false.
a ≤ b

© 2017 The College Board


119
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

Instruction Explanation
Relational and Boolean Operators (continued)
Text: Evaluates to true if condition is false;
NOT condition otherwise evaluates to false.
Block:

Text: Evaluates to true if both condition1


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

Text: Evaluates to true if condition1 is


condition1 OR condition2 true or if condition2 is true or if
both condition1 and condition2 are
Block:
true; otherwise, evaluates to false.

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

© 2017 The College Board


120
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

Instruction Explanation
Selection (continued)
Text: The code in first block of
IF (condition) statements is executed if the Boolean
{ expression condition evaluates to true;
<first block of statements> otherwise, the 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:

Text: The code in block of statements


REPEAT UNTIL (condition) is repeated until the Boolean expression
{ condition evaluates to true.
<block of statements>
}
Block:

© 2017 The College Board


121
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

Instruction Explanation
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.
list[i] The 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


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

Text: The variable item is assigned the value of


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

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
Block:
at 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:

© 2017 The College Board


122
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

Instruction Explanation
List Operations (continued)
Text: Removes the item at index i in list and
REMOVE (list, i) shifts to the left any values at indices greater
Block: than i. The length of list is decreased by 1.

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
parameter2, ...) programming instructions.
{
<instructions>
}
Block:

Text: A procedure, name, takes zero or more


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

© 2017 The College Board


123
AP ®
CapstoneScience
AP Computer ProgramPrinciples Exam Reference Sheet Course and Exam Description

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


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

© 2017 The College Board


124

You might also like