Question 1 of 10
PROCEDURE tip(amount, rate) returns amount * rate. What does tip(40, 0.2) return?
- A. 0.2
- B. 200
- C. 8
- D. 40
PROCEDURE tip(amount, rate) returns amount * rate. What does tip(40, 0.2) return?
Consider:
PROCEDURE mid(a, b)
{
RETURN ((a + b) / 2)
}
x ← mid(8, 2)
DISPLAY(x)
What is displayed?
A procedure minutesToHours(m) is documented to return m / 60. A programmer later rewrites the body to use repeated subtraction of 60 but keeps the same numeric return for every m. Which statement is true?
Which call correctly uses PROCEDURE circleArea(r), documented to return 3.14 * r * r, to store the area of a circle with radius 5 in variable a?
PROCEDURE sign(n) returns 1 if n > 0, returns -1 if n < 0, and returns 0 if n = 0. What does sign(-7) return?
The table shows results from PROCEDURE combo(x, y), which returns x * y + y.
| x | y | combo(x, y) |
|---|---|---|
| 2 | 3 | 9 |
| 4 | 1 | 5 |
| 5 | 2 | ? |
What is combo(5, 2)?
Why do parameters help when writing procedures?
Consider:
PROCEDURE step(n)
{
RETURN (n - 1)
}
PROCEDURE twiceStep(n)
{
RETURN (step(step(n)))
}
What does twiceStep(10) return?
A team documents that PROCEDURE safeDivide(a, b) returns a / b when b ≠ 0 and returns 0 when b = 0. Which call matches that contract for inputs a = 8 and b = 0?
Which incomplete line correctly returns the length of list nums from a procedure?