APCSP UNIT 7 Final Exam Review

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

16

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

How many values can a function return at a time?

1

You have imported a library with the birthMonth() function. Based on the API, how many strings are entered to calculate the birth month?// calculate birth month based on the day of the month, day of the week, and the birth year// dayMonth {number} - a day of a month from 1 to 31// dayWeek {string} - the name of the day of the week// year {number} - the birth year// return {string} - the month you were bornBirthdayLibrary.birthMonth(dayMonth, dayWeek, year);

1

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.

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

API

A Function can have:

Any of these options is acceptable IE = Parameters, but no return values No parameters and no return values Return values, but no parameters Parameters and return values

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

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.

This algorithm is intended to display a single message based on the temperature. Which works as intended?

Only the left algorithms works correctly.

this function checks if a character is a vowel. If it is, it returns true. Otherwise, it returns false.Where should return false; be written in the code?function checkVowel(character){ var vowels = ["a", "e", "i", "o", "u"]; for(var i=0; i<vowels.length; i++){ if(vowels[i] == character){ return true; OPTION A } OPTION B } OPTION C}OPTION D

Option C

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. health ← health + 10 IF(health > 100){ health ← 100 } food ← food + 1 IF(food > 80){ food ← 80 } knowledge ← knowledge + 5 IF(knowledge > 25){ knowledge ← 25 } The game program's author would like to write a procedure that could be used to update any variable in the game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of the procedure is shown below. myScore ← updateScore(myScore, myAmount, myLimit) Which of the following is a correct implementation of updateScore ?

PROCEDURE updateScore(score, amount, limit){ score ← score + amount IF(score > limit){ score ← limit } RETURN(score) }

Which of the following are benefits of procedural abstraction? Select two answers.

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.

A/An ______ is the value passed to the parameter

argument

Consider the following procedure. Procedure CallExplanationdrawCircle(xPos, yPos, rad)Draws a circle on a coordinate grid with center (xPos, yPos) and radius rad The drawCircle procedure is to be used to draw the following figure on a coordinate grid. 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)

listAverage() returns the average number in a list. Which of these functions does this correctly?

for loop } return } NOT for loop } } return

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

library

The following procedure was developed to determine if a list contains a negative number. If the list contains a negative number it should return true, otherwise it should return false. 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? 01 PROCEDURE checkNegative(list)02 {03 hasNegative <- true04 FOR EACH number IN list05 {06 IF(number < 0)07 {08 hasNegative <- true09 } 10 }11 RETURN(hasNegative)12 }

line 03

his 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];

Dividing a program into separate subprograms (such as libraries) is known as:

modularity

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;

Consider the following procedures, which are used to control a device that draws lines on paper. Procedure CallExplanationpenDown()Places the device's pen on the paper so that a line is drawn when the device movespenUp()Lifts the device's pen off of the paper so that no line is drawn when the device movesgoForward(x)Moves the device forward x unitsturnRight(x)Rotates the device in place x degrees clockwise (i.e., makes an in-place right turn) Consider the goal of using the device to produce the following drawing, where each line shown has a length of 10 units and the horizontal lines are 10 units apart. The device is positioned at the upper-left corner of a sheet of paper and is facing right. Which of the following code segments will produce the drawing shown?

penDown() goForward(10) penUp() turnRight(90) goForward(10) turnRight(90) penDown() goForward(10)

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 answer is NOT api

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

removes procedural abstraction

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 is one of the benefits of using a library in a program?

simplifies creating a complex program

Consider the following procedures. PROCEDURE proc1(str){ DISPLAY(str) DISPLAY("happy") } PROCEDURE proc2(str1, str2){ proc1(str2) DISPLAY(str1) } What is displayed as a result of the procedure call proc2("birthday", "to you") ?

to you happy birthday

The drawCircle procedure is to be used to draw the following figure on a coordinate grid. Which of the following code segments can be used to draw the figure? Select two answers.

x ← 4 y ← 1 r ← 0 REPEAT 3 TIMES{ drawCircle(x, y, r) r ← r + 1 y ← y + 1 } AND x ← 4 y ← 4 r ← 3 REPEAT 3 TIMES{ drawCircle(x, y, r) y ← y - 1 r ← r - 1 } // x ← 4 y ← 4 r ← 3 REPEAT 3 TIMES{ drawCircle(x, y, r) y ← y - 1 r ← r - 1 }


Kaugnay na mga set ng pag-aaral

PEDs Chapt 5 Growth and Development of the Preschooler

View Set

American Strengths and Weaknesses

View Set

Physic Ch 15 & 16 conceptual problems

View Set