Developing Procedures MCQ Practice

Question 1 of 10

PROCEDURE tip(amount, rate) returns amount * rate. What does tip(40, 0.2) return?

  1. A. 0.2
  2. B. 200
  3. C. 8
  4. D. 40

Question 2 of 10

Consider:

PROCEDURE mid(a, b)
{
    RETURN ((a + b) / 2)
}
x ← mid(8, 2)
DISPLAY(x)

What is displayed?

  1. A. 8
  2. B. 10
  3. C. 2
  4. D. 5

Question 3 of 10

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?

  1. A. Call sites may stay the same because they depend on the documented result, not the subtraction steps.
  2. B. The new body is illegal because procedures cannot change after first use.
  3. C. Callers must pass one fewer argument after any internal rewrite.
  4. D. Every DISPLAY that called minutesToHours must be deleted.

Question 4 of 10

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?

  1. A. a ← circleArea
  2. B. a ← circleArea(5)
  3. C. a ← circleArea(5, 5)
  4. D. circleArea(5) ← a

Question 5 of 10

PROCEDURE sign(n) returns 1 if n > 0, returns -1 if n < 0, and returns 0 if n = 0. What does sign(-7) return?

  1. A. 1
  2. B. 0
  3. C. -1
  4. D. -7

Question 6 of 10

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

  1. A. 14
  2. B. 7
  3. C. 10
  4. D. 12

Question 7 of 10

Why do parameters help when writing procedures?

  1. A. They let one procedure work for many different argument values.
  2. B. They force every caller to edit the procedure body before each call.
  3. C. They remove the need for a procedure name.
  4. D. They prevent a procedure from ever returning a value.

Question 8 of 10

Consider:

PROCEDURE step(n)
{
    RETURN (n - 1)
}
PROCEDURE twiceStep(n)
{
    RETURN (step(step(n)))
}

What does twiceStep(10) return?

  1. A. 11
  2. B. 8
  3. C. 9
  4. D. 10

Question 9 of 10

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?

  1. A. safeDivide(0, 8) is the only legal call when zeros appear.
  2. B. The call must crash because division by zero is required.
  3. C. safeDivide(8, 0) returns 0 according to the documentation.
  4. D. safeDivide(8, 0) must return 8.

Question 10 of 10

Which incomplete line correctly returns the length of list nums from a procedure?

  1. A. RETURN (INSERT(nums, 1, 0))
  2. B. DISPLAY(LENGTH(nums))
  3. C. RETURN (nums)
  4. D. RETURN (LENGTH(nums))