Six original Cambridge-style questions on subroutines in 0478 pseudocode, with mark points.
Explain the difference between a procedure and a function, including how each is called.
Describe what is meant by a local variable and a global variable.
Write a function Average that takes three integer parameters and returns their mean as a real number.
FUNCTION Average(A : INTEGER, B : INTEGER, C : INTEGER) ✓RETURNS REAL at the end of the header ✓RETURN (A + B + C) / 3 (brackets needed) ✓ENDFUNCTION ✓State the output of this pseudocode.
FUNCTION Double(N : INTEGER) RETURNS INTEGER
RETURN N * 2
ENDFUNCTION
PROCEDURE Show(N : INTEGER)
OUTPUT "Value: ", N
ENDPROCEDURE
DECLARE X : INTEGER
X ← Double(3)
CALL Show(X + 1)
CALL Show(Double(X))Write a procedure Greet with a STRING parameter Name and an INTEGER parameter Times that outputs "Hello " followed by the name, Times times. Then write a statement that calls it for the name Sam, twice.
PROCEDURE Greet(Name : STRING, Times : INTEGER) ✓FOR Count ← 1 TO Times, OUTPUT "Hello ", Name, NEXT Count, ENDPROCEDURE ✓CALL Greet("Sam", 2) ✓A student writes CALL Total ← Add(2, 3), where Add is a function. Explain what is wrong and correct it.
Total ← Add(2, 3). ✓Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.