Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
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 | |
|---|---|---|
| 1DECLARE Total : INTEGER (inside PROCEDURE ShowTotal) | AA local variable: it exists only inside this subroutine, so no other part of the program can change it by mistake | |
| 2FUNCTION AddTax(Price : REAL) RETURNS REAL | BOUTPUT Double(5) // should output 10 | |
| 3Two subroutines can each use a local variable with the same name without affecting each other | CThe procedure changes the global variable Score by mistake, which can break other parts of the program. Use a local variable instead. | |
| 4A subroutine that uses only local variables and parameters can be tested on its own | DThe value is passed in as a parameter, so the function does not rely on a global variable and can be tested alone | |
| 5Score ← 0 (global) PROCEDURE Reset() Score ← 100 ENDPROCEDURE | EThe function depends on global variables Width and Height, so it is hard to test alone. Pass them in as parameters instead. | |
| 6FUNCTION Area() RETURNS INTEGER RETURN Width * Height ENDFUNCTION | FPROCEDURE A() DECLARE i : INTEGER ... PROCEDURE B() DECLARE i : INTEGER |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
local variable — A variable declared inside a subroutine. It keeps the subroutine self-contained, so changing it cannot accidentally alter other parts of the program, and the subroutine is easier to test alone.PROCEDURE AddBonus(Score : INTEGER)
DECLARE NewScore : INTEGER
NewScore ← Score + 10FUNCTION AddTax(Price : REAL) RETURNS REAL
DECLARE Total : REAL
Total ← Price * 1.2PROCEDURE Reset()
DECLARE Count : INTEGER
Count ← 0FUNCTION Square(N : INTEGER) RETURNS INTEGER
RETURN N * N
ENDFUNCTION// Test Square alone: expect 16
OUTPUT Square(4)