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 | |
|---|---|---|
| 1FUNCTION AddTax(Price : REAL) RETURNS REAL RETURN Price * 1.15 ENDFUNCTION | AThe tax calculation is copied into three places, so a rate change needs three edits. Put it in one function and call it instead. | |
| 2Total1 ← Price1 * 1.15 Total2 ← Price2 * 1.15 Total3 ← Price3 * 1.15 | BCALL ShowScore(Score) | |
| 3A bug fixed once inside a subroutine is fixed for every place that calls it | CThe same calculation is copied three times, so a new tax rate must be changed in every copy. | |
| 4Missing one copy of repeated code after a change gives inconsistent results | DOne line calls AddTax but the other copies the calculation. If the rate in AddTax changes, the second line will not update and the results will be inconsistent. Use AddTax for both. | |
| 5Cost1 ← Price1 * 1.15 Cost2 ← Price2 * 1.15 Cost3 ← Price3 * 1.15 | EThe tax rate is written in one function, so changing 1.15 here updates every call to AddTax at once. | |
| 6OUTPUT AddTax(Price1) OUTPUT Price2 * 1.15 | FTotal1 ← Price1 * 1.20 Total2 ← Price2 * 1.15 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
single point of change — Code kept in one subroutine is edited once, so every CALL gets the update. Repeated copies must each be changed, and missing one gives inconsistent results.FUNCTION AddTax(Price : REAL) RETURNS REAL
RETURN Price * 1.2
ENDFUNCTIONOUTPUT AddTax(Cost1)
OUTPUT AddTax(Cost2)
OUTPUT AddTax(Cost3)PROCEDURE ShowPrice(Cost : REAL)
OUTPUT AddTax(Cost)
ENDPROCEDUREOUTPUT Price1 * 1.25
OUTPUT Price2 * 1.25
OUTPUT Price3 * 1.25FUNCTION IsAdult(Age : INTEGER) RETURNS
BOOLEAN
RETURN Age >= 18
ENDFUNCTION