AP CSP UNIT 2

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/51

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 5:08 AM on 1/29/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

52 Terms

1
New cards

what helps when writing code?

better organization

2
New cards

how does better organization help with code?

helps to debug and build upon

3
New cards

functions that have what, help simplify code?

parameters and return values

4
New cards

how many values can functions return at once?

only one

5
New cards

what is a parameter?

a variable in a function definition that is used as a placeholder for values that will be passed through the function

6
New cards

what is an argument?

the value passed to the parameter

7
New cards

what does a return do?

it is used to return the flow of control to the point where the function was called. it also returns the value of an expression.

8
New cards

what is MOD used for?

to determine if a number is divisible by another number

9
New cards

what is procedural abstraction

the process of extracting shared features to generalize functionality

10
New cards

using parameters allows what?

it allows the functions to be generalized

11
New cards

using procedural abstraction helps what?

it helps improve code readability

12
New cards

what do parameters and return values help us do?

they help us write code that is neater, and works in a larger number of scenarios

13
New cards

what is a library?

a collection of functions that can be used in many different programs

14
New cards

a library should include what?

how each function works, a complete list of procedures, and what (if anything) will be returned, those are called API's

15
New cards

what is an API?

specifications for how the functions in a library behave and can be used

16
New cards

why is testing useful?

it helps the user understand the behavior of the function and is helpful for debugging

17
New cards

what are some benefits of using algorithms?

they help reduce development time, testing, and they simplify the finding of errors

18
New cards

what is modularity?

the subdivision of a computer program into separate programs

19
New cards

what do libraries help with?

they help the programmer collaborate, reuse code, and write simple programs

20
New cards

what do parameters help with?

they allow functions to run in predictable ways without impacting anything, help communicate what the code is supposed to do, and they make functions more flexible

21
New cards

The procedure below will be called twice with two numbers provided as arguments to the parameter myNumber. Which of the following pair of numbers will mystery return the same value?

100 and 200

22
New cards

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

removes procedural abstraction

23
New cards

Which term refers to a solution to a large problem that is based on the solutions of smaller subproblems?

procedural abstraction

24
New cards

What will be printed to the console after this program runs?

[0, 3, 6, -1, 9]

25
New cards

Which code segment results in "true" being returned if a number is even? Replace "MISSING CONDITION" with the correct code segment.

function isEven(num){

if(MISSING CONDITION){ return true;

} else {

return false; }

}

num % 2 ==0;

26
New cards

Algorithms can be created in all the following ways EXCEPT:

removing sequencing, selection, and iteration from an algorithm

27
New cards

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

moveElement("button1", "down", 25);

28
New cards

This function finds the minimum number in a list. What should be replaced with in order for this function to operate as expected?

function min(numList){

var min = numList[0];

for(var i=0; i

}

}

return min;

}

min = numList[i];

29
New cards

You have imported a library with the birthMonth() function. Based on the API, how many strings are entered to calculate the birth month?

-3

-0

-4

-1

1

30
New cards

The figure below shows a robot in a grid of squares. The robot is represented as a triangle, which is initially facing upward. The robot can move into a white or gray square but cannot move into a black region.

MoveAndTurn 2, 1

MoveAndTurn 4, 3

MoveAndTurn 2, 0

31
New cards

A game program contains the following code to update three score variables, health, food, and knowledge. The maximum values for the three variables are 100, 80, and 25, respectively.

PROCEDURE updateScore(score, amount, limit){

score ← score + amount

IF(score > limit){

score ← limit

}

RETURN(score)

32
New cards

Which of the following are benefits of procedural abstraction?

Procedural abstraction makes it easier for people to read computer programs.

Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

33
New cards

Which of the following code segments can be used to draw the figure?

x ← 4

y ← 1

r ← 0

REPEAT 3 TIMES{

r ← r + 1

y ← y + 1

drawCircle(x, y, r)

}

x ← 4

y ← 4

r ← 3

REPEAT 3 TIMES{

drawCircle(x, y, r)

y ← y - 1

r ← r - 1

}

34
New cards

A student has a data file containing 10,000 numerical values. The student is writing a program to compute the average of the numbers contained in the file. Which of the following procedures is most likely to be useful in the student's program?

A procedure that returns the sum of the values in the file

35
New cards

Let the value of the variable x be 2, the value of the variable y be 2, and the value of the variable r be 1. Which of the following code segments can be used to draw the figure?

drawCircle(x, y, r)

drawCircle(x, y + 3, r)

drawCircle(x + 3, y, r)

drawCircle(x + 3, y + 3, r)

36
New cards

Which of the following procedures would be most useful as part of a program to determine whether a word appears in two different text files?

A procedure isFound, which takes a word and a text file as input and returns true if the word appears in the text file

37
New cards

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

to you happy birthday

38
New cards

A student is writing a program that is intended to replace each negative value in a particular column of a spreadsheet with the value 0. Which of the following procedures is most likely to be useful in the student's program?

A procedure findNegative, which returns the row number of the first negative value that appears in the column or -1 if there are no negative values.

39
New cards

An error was made in writing this function so that it does not work as intended. Which line of code would need to be fixed in order for the function to work as designed?

Line 03

Line 06

Line 011

Line 08

Line 03

40
New cards

Which function calls would provide the most helpful test of this function?

findMin(-1,1)findMin(1,-1)findMin(1,1)

41
New cards

Is the following function is a good candidate to be placed in a library?

No. It references variables ( player1Points , player2Points ) that are most likely global variables in the original program.

42
New cards

What will print to the console after running this code segment?

18

16

15

21

16

43
New cards

What is printed to the console?console.log(15 % 4)

3

2

4

1

3

44
New cards

A computer science student completes a program and asks a classmate for feedback. The classmate suggests rewriting some of the code to include more procedural abstraction. Which of the following is NOT a benefit of procedural abstraction?

making the code run faster

45
New cards

Which of the following is a true statement about the student's use of the computer scientist's search procedure?

The student is reusing the computer scientist's procedural abstraction by knowing what the procedure does without knowing how it does it.

46
New cards

A/An ______ is the value passed to the parameter

argument

47
New cards

A/An ______ is 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.

return

48
New cards

A/An ______ is a variable in a function definition and is used as a placeholder for values that will be passed through the function.

parameter

49
New cards

A/An ______ contains specifications for how functions in a library behave and can be used.

API

50
New cards

This provides a name for a process and allows the procedure (function) to be used only knowing what it does, and not necessarily how it does it.

procedural abstraction

51
New cards

A/An ______ is a group of functions (procedures) that may be used in creating new programs

library

52
New cards

which of the following procedures would be most useful as a part of a program that determines GPA?

calQuotient