CSP calling procedures/developing procedures quiz

0.0(0)
Studied by 16 people
0%Big Idea 3 Mastery
0%Exam Mastery
Build your Mastery score
multiple choiceAP Practice
Supplemental Materials
call kaiCall Kai
Card Sorting

1/11

flashcard set

Earn XP

Description and Tags

ap collegeboard unit 3 3.12 and 3.13

Last updated 1:29 AM on 10/30/24
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

12 Terms

1
New cards
<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)

2
New cards
<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)

3
New cards
<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

4
New cards
<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)

5
New cards

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

6
New cards

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

7
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.

8
New cards

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

9
New cards
<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

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

11
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

12
New cards

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.

Explore top notes

note
Breathing and Exchange of Gases
Updated 1239d ago
0.0(0)
note
Letter #24
Updated 562d ago
0.0(0)
note
AP World History
Updated 553d ago
0.0(0)
note
Foundation of Programming (AQA)
Updated 623d ago
0.0(0)
note
If, My Darling
Updated 1134d ago
0.0(0)
note
Chapter 21: Healthcare
Updated 1283d ago
0.0(0)
note
Breathing and Exchange of Gases
Updated 1239d ago
0.0(0)
note
Letter #24
Updated 562d ago
0.0(0)
note
AP World History
Updated 553d ago
0.0(0)
note
Foundation of Programming (AQA)
Updated 623d ago
0.0(0)
note
If, My Darling
Updated 1134d ago
0.0(0)
note
Chapter 21: Healthcare
Updated 1283d ago
0.0(0)

Explore top flashcards

flashcards
Wheelock's Latin Vocabulary
791
Updated 1058d ago
0.0(0)
flashcards
Lvl 3: 3/3/23: U3, L1: Week C
20
Updated 1130d ago
0.0(0)
flashcards
spanish foods
60
Updated 1086d ago
0.0(0)
flashcards
Au restaurant
61
Updated 1267d ago
0.0(0)
flashcards
Frans: L'art et la culture
146
Updated 1055d ago
0.0(0)
flashcards
Chem Chapter 6 Williams
22
Updated 1225d ago
0.0(0)
flashcards
Latin and Greek Roots List 1-3
75
Updated 345d ago
0.0(0)
flashcards
Wheelock's Latin Vocabulary
791
Updated 1058d ago
0.0(0)
flashcards
Lvl 3: 3/3/23: U3, L1: Week C
20
Updated 1130d ago
0.0(0)
flashcards
spanish foods
60
Updated 1086d ago
0.0(0)
flashcards
Au restaurant
61
Updated 1267d ago
0.0(0)
flashcards
Frans: L'art et la culture
146
Updated 1055d ago
0.0(0)
flashcards
Chem Chapter 6 Williams
22
Updated 1225d ago
0.0(0)
flashcards
Latin and Greek Roots List 1-3
75
Updated 345d ago
0.0(0)