AP CSP UNIT 2

Ace your homework & exams now with Quizwiz!

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.

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

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

A/An ______ is the value passed to the parameter

argument

what helps when writing code?

better organization

using parameters allows what?

it allows the functions to be generalized

using procedural abstraction helps what?

it helps improve code readability

how many values can functions return at once?

only one

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

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

What will print to the console after running this code segment? 18 16 15 21

16

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

3

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.

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

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

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

API

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

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)

what is a library?

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

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

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)

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

why is testing useful?

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

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.

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

library

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

This function finds the minimum number in a list. What should <MISSING CODE SEGMENT> be replaced with in order for this function to operate as expected? function min(numList){ var min = numList[0]; for(var i=0; i<numList.length; i++){ if(numList[i] < min){ <MISSING CODE SEGMENT> } } return min; }

min = numList[i];

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

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

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;

functions that have what, help simplify code?

parameters and return values

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

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

procedural abstraction

what is an API?

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

what is procedural abstraction

the process of extracting shared features to generalize functionality

what is modularity?

the subdivision of a computer program into separate programs

what is an argument?

the value passed to the parameter

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

what are some benefits of using algorithms?

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

what do libraries help with?

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

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

to you happy birthday

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 }

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

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.

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.

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

calQuotient

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

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

how does better organization help with code?

helps to debug and build upon

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

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

removes procedural abstraction

Algorithms can be created in all the following ways EXCEPT:

removing sequencing, selection, and iteration from an algorithm

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

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

what is MOD used for?

to determine if a number is divisible by another number


Related study sets

Pharmacology Chapter 19: NCLEX Questions

View Set

PR Writing - Publicity Photos & Infographics

View Set

CHAPTER 11: ADJECTIVES USED AS NOUNS

View Set

ECO231 Chap 11, ECO231 Chapter 10, Chapter 9, ECon

View Set

ServSafe Powerpoint 7: The Flow of Food- Storage

View Set

NC Life Insurance Practice Exam Questions 2

View Set

Human Physiology - Chapter 5, Membrane Transport

View Set

Info and Network Security Chapter 8-15

View Set

Assessment of Skin, Hair, and Nails

View Set