Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Pseudocode FUNCTION ... RETURNS ... RETURN ... ENDFUNCTION worksheet is part of the IGCSE Computer Science 0478 — 7b Decomposition and Sub-systems journey. Print it as a booklet?
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1FUNCTION Double(Num : INTEGER) RETURNS INTEGER | ASends the calculated value Num multiplied by 2 back to the part of the program that called the function | |
| 2RETURN Num * 2 | BStarts a function called Double that takes an integer parameter Num and will send back an integer value | |
| 3A function is closed with ENDFUNCTION after its RETURN line, and the function body is indented | CThe header is missing RETURNS INTEGER, so the type of value sent back is not stated | |
| 4A function call can be used inside an expression because it gives back a value | DFUNCTION Square(N : INTEGER) RETURNS INTEGER RETURN N * N ENDFUNCTION | |
| 5FUNCTION Double(Num : INTEGER) RETURN Num * 2 ENDFUNCTION | EOUTPUT is used instead of RETURN, so the value is only displayed and not sent back to the caller | |
| 6FUNCTION Double(Num : INTEGER) RETURNS INTEGER OUTPUT Num * 2 ENDFUNCTION | FTotal ← Square(5) + 10 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FUNCTION Name(Param : TYPE) RETURNS TYPE — Starts a function that takes a typed parameter and RETURNS a value of the stated type. RETURN sends the value back, ENDFUNCTION closes it, and you can call it inside an expression.FUNCTION Square(N : INTEGER) RETURNS INTEGER
RETURN N * N
ENDFUNCTIONFUNCTION Half(N : INTEGER) RETURNS REAL
RETURN N / 2
ENDFUNCTIONFUNCTION Cube(N : INTEGER) RETURNS INTEGER
RETURN N * N * N
ENDFUNCTIONFUNCTION AddVAT(P : REAL) RETURNS REAL
RETURN P * 1.2
ENDFUNCTIONINPUT Price
Total ← AddVAT(Price) + 5
OUTPUT Total