wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP unit 7 review

Total questions: 26

Worksheet time: 7hrs 30mins

Name
Class
Date
1.

After running the following code segment, what is contained in the array data?

data = [5, 2, 3, 6, 7]

i = 1

REPEAT UNTIL (i = 5)

{

data[i] = data[i+1]

i = i + 1

}

a)

A. [5, 2, 3, 6, 7]

b)

B. [2, 3, 6, 7, 7]

c)

C. [2, 3, 6, 7, 7]

d)

D. [5, 6, 7, 7, 7]

e)

E. [5, 2, 3, 6, 6]

2.

Consider the procedure below, which takes two parameters: a list data and a number n.

Which of the following best describes what the procedure does?

PROCEDURE findIndex(data, n)

{

i = 1

REPEAT UNTIL (i = LENGTH(data))

{

IF (data[i] = n)

{

DISPLAY(i)

}

i = i + 1

}

}

a)

A. Displays the value at index n

b)

B. Displays the index of the first occurrence of n in the list

c)

C. Displays the index of the last occurrence of n in the list

d)

D. Displays the index of every occurrence of n in the list

e)

E. Displays true if n is in the list

3.

Which of the following best describes the value returned by the procedure below?

PROCEDURE countDescending(data)

{

count = 0

i = 1

REPEAT UNTIL (i = LENGTH(data))

{

IF (data[i] > data[i+1])

{

count = count + 1

}

i = i + 1

}

RETURN(count)

}

a)

A. The procedure returns true when data is in descending order

b)

B. The procedure returns false when data is in ascending order

c)

C. The procedure returns the number of times adjacent items are in descending order

d)

D. The procedure returns how long it takes to find two numbers in descending order

e)

E. The procedure counts how long it takes to find two numbers in ascending order and returns that number

4.

Which of the following should replace the <MISSING CODE> in the following procedure to complete it?

PROCEDURE playGame()

{

scores = []

REPEAT UNTIL ( totalScore(scores) >= 100 )

{

score1 = player1Score()

APPEND(scores, score1)

score2 = player2Score()

APPEND(scores, score2)

}

}

PROCEDURE totalScore(scores)

{

total = 0

FOR EACH score IN scores

{

total = total + score

}

<MISSING CODE>

}

a)

A. DISPLAY(total)

b)

B.

DISPLAY("game over")

c)

C. RETURN(total)

d)

D. RETURN("game over")

e)

E. Nothing. Procedure works as is.

5.

What is the output of the following function?

PROCEDURE max(a, b, c)

{

IF (a >= b AND a >= c)

{

RETURN(a)

}

ELSE IF (b >= a AND b >= c)

{

RETURN(b)

}

ELSE

{

RETURN(c)

}

}

a)

A. Returns the smallest of the three input values

b)

B. Returns the middle of the three input values

c)

C. Returns the largest of the three input values

d)

D. Returns the average of the three input values

e)

E. Always returns c

6.

Algorithms can be created in all of the following ways EXCEPT:

a)

A. creating from an idea

b)

B. combining existing algorithms

c)

C. modifying existing algorithms

d)

D. removing iteration from an algorithm

7.

Using existing algorithms as building blocks for new algorithms has all the following benefits EXCEPT:

a)

A. Reduces development time

b)

B. Reduces testing

c)

C. Removes procedural abstraction

d)

D. Simplifies debugging

8.

What is one of the benefits of using a library in a program?

a)

A. Simplifies creating a complex program

b)

B. Increases development time

c)

C. Removes all testing

d)

D. Reduces abstractions in the program

9.

Which function call correctly follows the instructions laid out in the API?

function moveObject(element, direction, distance);

a)

A. moveObject("box", 20, "left")

b)

B. moveObject("box" , "up" , 15)

c)

C. moveObject("box", "left", "10")

d)

D. moveObject("box" , "right", 10.5)

10.

Dividing a program into separate subprograms is known as:

a)

A. API

b)

B. Iteration

c)

C. Modularity

d)

D. Documentation

11.

Which function correctly returns the average of the numbers in a list numbers?

a)

A.

PROCEDURE listAverage(numbers)

{

sum = 0

FOR EACH num IN numbers

{

sum = sum + num

}

RETURN(sum / LENGTH(numbers))

}

b)

B.

PROCEDURE listAverage(numbers)

{

sum = 0

FOR EACH num IN numbers

{

sum = sum + num

}

RETURN(sum / 2)

}

c)

C.

PROCEDURE listAverage(numbers)

{

sum = 0

FOR EACH num IN numbers

{

sum = sum + num

}

RETURN(sum)

}

d)

D.

PROCEDURE listAverage(numbers)

{

RETURN(LENGTH(numbers))

}

12.

What is printed to the console?

console.log(20 % 6);

a)

A. 2

b)

B. 4

c)

C. 1

d)

D. 3

13.

Which term refers to a solution to a large problem based on smaller subproblems?

a)

A. Procedural abstraction

b)

B. API

c)

C. Parameter

d)

D. Library

14.

Where should the return false; statement be placed in the function below?

function checkVowel(character)

{

var vowels = ["a", "e", "i", "o", "u"];

for(var i = 0; i < vowels.length; i++)

{

if(vowels[i] == character)

{

return true;

}

}

<MISSING CODE>

}

a)

A. Inside the for loop after return true;

b)

B. Inside the for loop before return true;

c)

C. After the for loop but still inside the function

d)

D. Outside the function

15.

What should replace <MISSING CODE> in the function below to correctly find the minimum number in a list?

function min(numList)

{

var min = numList[0];

for(var i = 1; i < numList.length; i++)

{

if(numList[i] < min)

{

<MISSING CODE>

}

}

return min;

}

a)

A. numList[i] = min;

b)

B. min = numList[i];

c)

C. min = numList;

d)

D. numList = min;

16.

Which condition results in a function returning "true" when the number is even?

function isEven(num)

{

if(MISSING CONDITION)

{

return true;

}

else

{

return false;

}

}

a)

A. num % 2 == 0

b)

B. num % 0 == 2

c)

C. num % 1 == 0

d)

D. num % 1 == 2

17.

What code segment guarantees the robot will avoid obstacles and reach the goal?

a)

A.

rotateLeft();

canMove("forward");

moveForward();

rotateRight();

canMove("forward");

moveForward();

b)

B.

canMove("forward");

moveForward();

rotateLeft();

moveForward();

c)

C.

moveForward();

rotateLeft();

moveForward();

rotateRight();

canMove("forward");

d)

D.

rotateLeft();

moveForward();

canMove("forward");

moveForward();

18.

What will be printed to the console after running the following program?

var nums = [1, 4, 7, 10, 13];

function adjustNums(list, add, subtract)

{

for(var i = 0; i < list.length; i++)

{

if(list[i] % 2 == 0)

{

list[i] = list[i] + add;

}

else

{

list[i] = list[i] - subtract;

}

}

}

adjustNums(nums, 3, 2);

console.log(nums);

a)

A. [1, 4, 7, 10, 13]

b)

B. [3, 7, 7, 12, 13]

c)

C. [0, 7, 5, 13, 13]

d)

D. [3, 7, 5, 13, 11]

19.

What is a Parameter?

a)

used to return the flow of control to the point where the procedure (also known as a

function) was called and to return the value of expression.

b)

a group of functions (procedures) that may be used in creating new programs

c)

a variable in a function definition. Used as a placeholder for values that will be passed

through the function.

d)

The subdivision of a computer program into separate subprograms

20.

What is Procedural Abstraction?

a)

a process and allows a procedure to be used only knowing what it does, not how it does

it. Procedural abstraction allows a solution to a large problem to be based on the

solution of smaller subproblems. This is accomplished by creating procedures to solve

each of the subproblems.

b)

used to return the flow of control to the point where the procedure (also known as a

function) was called and to return the value of expression.

c)

a variable in a function definition. Used as a placeholder for values that will be passed

through the function.

21.

What is a Argument

a)

Extracting shared features to generalize functionality

b)

the value passed to the parameter

c)

specifications for how functions in a library behave and

can be used

d)

The subdivision of a computer program into separate subprograms

22.

What is an API?

a)

specifications for how functions in a library behave and

can be used

b)

a group of functions (procedures) that may be used in creating new programs

c)

the value passed to the parameter

d)

a variable in a function definition. Used as a placeholder for values that will be passed

through the function.

23.

What is a Library?

a)

a group of functions (procedures) that may be used in creating new programs

b)

used to return the flow of control to the point where the procedure (also known as a

function) was called and to return the value of expression.

c)

The subdivision of a computer program into separate subprograms

24.

What is a Return?

a)

a group of functions (procedures) that may be used in creating new programs

b)

a variable in a function definition. Used as a placeholder for values that will be passed

through the function.

c)

used to return the flow of control to the point where the procedure (also known as a

function) was called and to return the value of expression.

d)

Extracting shared features to generalize functionality

25.

What is Modularity?

a)

The subdivision of a computer program into separate subprograms

b)

a variable in a function definition. Used as a placeholder for values that will be passed

through the function.

c)

used to return the flow of control to the point where the procedure (also known as a

function) was called and to return the value of expression.

d)

a group of functions (procedures) that may be used in creating new programs

26.

the remainder when dividing

(a)