Question 1 of 5
(a) Write PROCEDURE celsiusToF(c) that returns 1.8 * c + 32. (b) Trace celsiusToF(10). (c) Explain what a caller does not need to know when using celsiusToF.
Responses receive AI feedback against a rubric after submission. Scores are practice estimates.
(a) Write PROCEDURE celsiusToF(c) that returns 1.8 * c + 32. (b) Trace celsiusToF(10). (c) Explain what a caller does not need to know when using celsiusToF.
PROCEDURE inRange(n, lo, hi) should return true when lo ≤ n ≤ hi and false otherwise. (a) Write the procedure. (b) Trace inRange(5, 1, 10) and inRange(0, 1, 10). (c) Give one example of another procedure that could call inRange to avoid duplicating the comparison.
A student has:
PROCEDURE mystery(a, b)
{
IF (a > b)
{
RETURN (a - b)
}
ELSE
{
RETURN (b - a)
}
}
(a) Trace mystery(3, 10) and mystery(10, 3). (b) State in one sentence what mystery computes. (c) Explain why renaming mystery to distance makes the abstraction clearer for callers.
Complete PROCEDURE countdown(n) so that it DISPLAYS n, n-1, ..., 1 and then RETURNs 0. Assume n is a positive integer. (a) Write the procedure using a loop. (b) Trace the DISPLAY outputs for countdown(3). (c) State the value returned to the caller.
PROCEDURE sumList(nums) should return the sum of all elements in list nums (1-based). (a) Write the procedure using FOR EACH or an index loop and RETURN. (b) Trace sumList([2, 4, 6]). (c) Explain one way procedural abstraction helps if the list format later changes but the procedure still returns the sum.