Consider the following code segment.
PROCEDURE combine(a, b)
{
RETURN(a + b * 2)
}
DISPLAY(combine(3, 4))What is displayed?
10
11
14
20
Was this exam question helpful?
Consider the following code segment.
PROCEDURE combine(a, b)
{
RETURN(a + b * 2)
}
DISPLAY(combine(3, 4))What is displayed?
10
11
14
20
Choose your answer
Was this exam question helpful?
In the procedure call greet("Sam"), the value "Sam" is best described as a(n):
parameter
argument
return value
procedure name
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE mystery(n)
{
IF(n > 0)
{
RETURN(n)
}
RETURN(0 - n)
}
DISPLAY(mystery(0 - 6))What is displayed?
-6
0
6
Nothing is displayed
Choose your answer
Was this exam question helpful?
Which two of the following are benefits of procedural abstraction? Select two answers.
A change to the logic only needs to be made in one place
Repeated code can be replaced by a single reusable procedure
The program is guaranteed to run faster
The program no longer needs any variables
Choose your answer
Was this exam question helpful?
A programmer notices the same five lines of code that calculate shipping cost appear in four different places in a program. Which change best demonstrates procedural abstraction?
Move the five lines into a procedure and call it from each of the four places
Copy the five lines a fifth time so all cases are covered
Add a comment above each of the four copies
Store the result in a different variable in each location
Choose your answer
Was this exam question helpful?
Consider the following procedure definition.
PROCEDURE repeatWord(word, count)
{
...
}In this definition, count is best described as a(n):
parameter
argument
return value
procedure name
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE triple(n)
{
RETURN(n * 3)
}
result ← triple(4)
DISPLAY(result)What value is displayed when this code segment is executed?
4
12
7
Nothing is displayed
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE sizeLabel(n)
{
IF(n ≥ 10)
{
RETURN("big")
}
RETURN("small")
}
DISPLAY(sizeLabel(10))What is displayed?
"small"
10
"big"
Nothing is displayed
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE maxOf(a, b)
{
IF(a > b)
{
RETURN(a)
}
RETURN(b)
}
DISPLAY(maxOf(7, 3) + maxOf(2, 9))What value is displayed?
12
10
18
16
Choose your answer
Was this exam question helpful?
A program contains three separate procedures named drawSquare5, drawSquare8, and drawSquare12, each of which draws a square of a fixed side length. Which change best demonstrates procedural abstraction through parameter generalization?
Replace the three procedures with one drawSquare(side) procedure that takes the side length as a parameter
Add a fourth procedure drawSquare20 for the next size that is needed
Rename the three procedures so their names are shorter
Add a comment above each of the three procedures describing what it draws
Choose your answer
Was this exam question helpful?
A procedure named showMenu takes no parameters. In AP CSP pseudocode, which line correctly calls this procedure so that its instructions run?
showMenu
showMenu()
CALL showMenu
PROCEDURE showMenu()
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE label(word, suffix)
{
RETURN(CONCAT(word, suffix))
}
DISPLAY(label("Row", "4"))What is displayed?
"Rown"
"name4"
"Row4"
"word4"
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE check(n)
{
IF(n MOD 2 = 0)
{
RETURN("even")
}
DISPLAY("odd")
RETURN("done")
}
DISPLAY(check(6))What is displayed when this code segment is executed?
odd
odd then done
done
even
Choose your answer
Was this exam question helpful?
Consider the following code segment.
PROCEDURE addTax(price)
{
RETURN(price + price * 0.1)
}
total ← 0
prices ← [20, 30]
FOR EACH p IN prices
{
total ← total + addTax(p)
}
DISPLAY(total)What value is displayed?
55
50
5
60
Choose your answer
Was this exam question helpful?