CSP calling procedures/developing procedures quiz

studied byStudied by 1 person
0.0(0)
Get a hint
Hint
<p>Consider the following procedure.</p><p><br>Procedure </p><p>CallExplanationdrawCircle(xPos, yPos, rad)</p><p>Draws a circle on a coordinate grid with center (xPos, yPos) and radius rad</p><p><br>The drawCircle procedure is to be used to draw the following figure on a coordinate grid.<br><br>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?</p>

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?

1 / 11

flashcard set

Earn XP

Description and Tags

ap collegeboard unit 3 3.12 and 3.13

12 Terms

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

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)

New cards
2
<p>Consider the following procedure.<br><br>drawLine(x1, y1, x2, y2) = Draws a line segment on a coordinate grid with endpoints at coordinates (x1, y1) and (x2, y2)<br><br>The drawLine procedure is to be used to draw the following figure on a coordinate grid.<br>Let the value of the variable xVal be 6 and the value of the variable yVal be 5. Which of the following code segments can be used to draw the figure?<br><br>A. drawLine(1, 5, xVal, yVal)<br>drawline(1, 5, xVal, yVal + 2)<br>drawline(1, 5, xVal, yVal + 2)<br><br>B. drawLine(1, 5, xVal, yVal)<br>drawline(1, 5, xVal, yVal + 2)<br>drawline(1, 5, xVal, yVal - 2)<br><br>C. drawLine(1, 5, xVal, yVal)<br>drawline(1, 5, xVal + 2, yVal + 2)<br>drawline(1, 5, xVal + 2, yVal - 2)<br><br>D. drawLine(1, 5, xVal, yVal)<br>drawline(1, 5, xVal + 2, yVal + 2)<br>drawline(1, 5, xVal - 2, yVal - 2)</p>

Consider the following procedure.

drawLine(x1, y1, x2, y2) = Draws a line segment on a coordinate grid with endpoints at coordinates (x1, y1) and (x2, y2)

The drawLine procedure is to be used to draw the following figure on a coordinate grid.
Let the value of the variable xVal be 6 and the value of the variable yVal be 5. Which of the following code segments can be used to draw the figure?

A. drawLine(1, 5, xVal, yVal)
drawline(1, 5, xVal, yVal + 2)
drawline(1, 5, xVal, yVal + 2)

B. drawLine(1, 5, xVal, yVal)
drawline(1, 5, xVal, yVal + 2)
drawline(1, 5, xVal, yVal - 2)

C. drawLine(1, 5, xVal, yVal)
drawline(1, 5, xVal + 2, yVal + 2)
drawline(1, 5, xVal + 2, yVal - 2)

D. drawLine(1, 5, xVal, yVal)
drawline(1, 5, xVal + 2, yVal + 2)
drawline(1, 5, xVal - 2, yVal - 2)

B. drawLine(1, 5, xVal, yVal)
drawline(1, 5, xVal, yVal + 2)
drawline(1, 5, xVal, yVal - 2)

New cards
3
<p>What is displayed as a result of the procedure call proc2("birthday", "to you") ?</p>

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

to you happy birthday

New cards
4
<p>Consider the following procedures, which are used to control a device that draws lines on paper.<br>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)<br>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.<br><br>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?</p>

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)

New cards
5

Consider the following procedure.
PROCEDURE doSomething(num1, num2)
{
DISPLAY(num1)
RETURN(num1)
DISPLAY(num2)
}
Consider the following statement.
DISPLAY(doSomething(10, 20))
What is displayed as a result of executing the statement above?

10 10

New cards
6

In the following procedure, the parameter str is a string and the parameter num is a number.

PROCEDURE printArgs(str, num)

{

DISPLAY(num)

DISPLAY(str)

DISPLAY(num)

}

Consider the following code segment. printArgs("**", 1) printArgs("*", 2) What is displayed as a result of executing the code segment?

1 ** 1 2 * 2

New cards
7

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.

New cards
8

A computer program contains code in several places that asks a user to enter an integer within a specified range of values. The code repeats the input request if the value that the user enters is not within the specified range. A programmer would like to create a procedure that will generalize this functionality and can be used throughout the program. The correct use of the procedure is shown below, where min is the least acceptable value, max is the greatest acceptable value, and promptString is the string that should be printed to prompt the user enter a value.


inputVal ←← getRange(min, max, promptString)


Which of the following is a correct implementation of the getRange procedure?

PROCEDURE getRange(min, max, promptString)
{
DISPLAY(promptString)
x ←← INPUT()
REPEAT UNTIL(x ≥ min AND x ≤ max)
{
DISPLAY(promptString)
x ←← INPUT()
}
RETURN(x)
}

New cards
9
<p>A student wrote the following procedure to calculate the sum of the integers from 1 to 5.<br>The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which represents any positive integer greater than 1.<br>Which of the following changes should be made to the procedure to meet the student's goal?<br>The procedure should take max as an input parameter.<br>The condition in the REPEAT UNTIL block should be changed to count &gt; max.<br>The condition in the REPEAT UNTIL block should be changed to max &lt; 5</p>

A student wrote the following procedure to calculate the sum of the integers from 1 to 5.
The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which represents any positive integer greater than 1.
Which of the following changes should be made to the procedure to meet the student's goal?
The procedure should take max as an input parameter.
The condition in the REPEAT UNTIL block should be changed to count > max.
The condition in the REPEAT UNTIL block should be changed to max < 5

I and II

New cards
10

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)
}

New cards
11

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

New cards
12

A student is developing a program that allows users to look up the definitions of words that appear in a book.
The student plans to perform a large number of searches through a dictionary containing words and their definitions. The student will use a procedure written by a computer scientist to quickly search the dictionary (and knows that the procedure will return a definition if one is available). The student cannot modify the search procedure written by the computer scientist but can call the procedure by supplying a word.
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.

New cards

Explore top notes

note Note
studied byStudied by 6 people
... ago
5.0(1)
note Note
studied byStudied by 48 people
... ago
5.0(1)
note Note
studied byStudied by 26 people
... ago
5.0(1)
note Note
studied byStudied by 138 people
... ago
5.0(1)
note Note
studied byStudied by 21 people
... ago
5.0(1)
note Note
studied byStudied by 14 people
... ago
5.0(1)
note Note
studied byStudied by 42 people
... ago
5.0(2)
note Note
studied byStudied by 815 people
... ago
5.0(1)

Explore top flashcards

flashcards Flashcard (63)
studied byStudied by 70 people
... ago
5.0(1)
flashcards Flashcard (48)
studied byStudied by 31 people
... ago
5.0(1)
flashcards Flashcard (57)
studied byStudied by 16 people
... ago
5.0(1)
flashcards Flashcard (68)
studied byStudied by 3 people
... ago
5.0(1)
flashcards Flashcard (79)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (61)
studied byStudied by 30 people
... ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 153 people
... ago
4.5(2)
flashcards Flashcard (302)
studied byStudied by 51 people
... ago
5.0(1)
robot