Explaining how subroutines make a program easier to maintain

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Explaining how subroutines make a program easier to maintain

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which answer about maintenance earns full marks?
A Subroutines make maintenance easier because a change is made once in the subroutine and every call uses the new code.
B Subroutines make maintenance easier because it is easier.
2. Which word links a benefit to its reason in an exam answer?
A and also
B because
3. A program prints a school header in 10 places. The header text must change. Which explanation is best?
A With a PrintHeader procedure, you edit one place because all 10 calls run that same procedure.
B With a PrintHeader procedure, it is quicker and simpler to update.
4. Which is a vague answer that would not earn full marks?
A It means a bug fixed in the subroutine is fixed for every call because the code is only written once.
B It makes the program easier to maintain.
5. A program has the VAT calculation copied 8 times with no subroutine. The VAT rate changes. What is the maintenance problem?
A All 8 copies must be found and edited, and missing one leaves a mistake.
B Only one line needs changing because the copies are linked.

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Subroutines make changes easier because the code is in one place. AThe reason just repeats the claim. It should name a specific benefit, such as one place to change, and explain it.
2Subroutines make it easier. BFUNCTION CalculateTotal(Price : REAL) RETURNS REAL RETURN Price * 1.2 ENDFUNCTION
3Use an example from the program: if the VAT rate changes, only the CalculateTotal function needs editing. CA vague answer: it gives no benefit and no reason, so it earns no marks.
4With subroutines, a repeated task is written once and called many times, so a fix is made once. DA full answer: it names a benefit (easier changes) and uses 'because' to give a reason (one place to edit).
5Answer: Subroutines are better and easier to use. EThis is vague. It names no benefit and gives no reason. Fix it by naming a benefit and adding 'because' with a reason.
6Answer: Subroutines are good for maintenance because they are good. FCALL ShowMenu() CALL ShowMenu() CALL ShowMenu()

Definitions

benefit because reason

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Benefit: one place to change _______ the code is written only once
2.
PROCEDURE PrintHeader() OUTPUT "Quiz Game" ____________
3.
CALL PrintHeader() ____ PrintHeader() OUTPUT "Next round"
4.
FUNCTION AddVAT(p : REAL) RETURNS REAL ______ p * 1.2 ENDFUNCTION
5.
Easy to test _______ each subroutine can be checked on its own.

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A PROCEDURE ShowBanner()
B OUTPUT "Welcome to Shop"
C ENDPROCEDURE
D ShowBanner()
Question 2
A // VAT rate: one place only
B FUNCTION Tax()
C RETURN 0.2
D ENDFUNCTION
E Cost ← 80 + 80 * Tax()
Question 3
A PROCEDURE Show(N : INTEGER)
B OUTPUT "Item ", N
C ENDFUNCTION
D CALL Show(5)
Question 4
A // Test Area() once, reuse it
B SmallRoom ← Area(3, 4)
C BigRoom ← CALL Area(10, 8)
D OUTPUT SmallRoom, BigRoom
Question 5
A PROCEDURE Print Header()
B OUTPUT "Class 10A Report"
C ENDPROCEDURE
D CALL PrintHeader()

Answer Key

Explaining how subroutines make a program easier to maintain
Section A: Quick Questions
Q1
A — Subroutines make maintenance easier because a change is made once in the subroutine and every call uses the new code.
Q2
B — because
Q3
A — With a PrintHeader procedure, you edit one place because all 10 calls run that same procedure.
Q4
B — It makes the program easier to maintain.
Q5
A — All 8 copies must be found and edited, and missing one leaves a mistake.
Section B: Match the Pairs
Q1
Subroutines make changes easier because the code is in one place. → A full answer: it names a benefit (easier changes) and uses 'because' to give a reason (one place to edit).
Q2
Subroutines make it easier. → A vague answer: it gives no benefit and no reason, so it earns no marks.
Q3
Use an example from the program: if the VAT rate changes, only the CalculateTotal function needs editing. → FUNCTION CalculateTotal(Price : REAL) RETURNS REAL RETURN Price * 1.2 ENDFUNCTION
Q4
With subroutines, a repeated task is written once and called many times, so a fix is made once. → CALL ShowMenu() CALL ShowMenu() CALL ShowMenu()
Q5
Answer: Subroutines are better and easier to use. → This is vague. It names no benefit and gives no reason. Fix it by naming a benefit and adding 'because' with a reason.
Q6
Answer: Subroutines are good for maintenance because they are good. → The reason just repeats the claim. It should name a specific benefit, such as one place to change, and explain it.
Section C: Definitions
Q1
benefit because reason — A full maintenance answer names a benefit of subroutines, such as one place to change, then uses because to give the reason, ideally with an example from the program, not just 'it is easier'.
Section D: Fill in the Blanks
Q1
Benefit: one place to change because the code is written only once
Q2
PROCEDURE PrintHeader() OUTPUT "Quiz Game" ENDPROCEDURE
Q3
CALL PrintHeader() CALL PrintHeader() OUTPUT "Next round"
Q4
FUNCTION AddVAT(p : REAL) RETURNS REAL RETURN p * 1.2 ENDFUNCTION
Q5
Easy to test because each subroutine can be checked on its own.
Section E: Spot the Error
Q1
D — A procedure call needs the CALL keyword. It should be CALL ShowBanner(). The banner text can then be changed in one place and every call shows the new text.
Q2
B — A function header must state the data type it returns. It should be FUNCTION Tax() RETURNS REAL. Changing the rate in one place then updates every call.
Q3
C — A procedure must finish with ENDPROCEDURE, not ENDFUNCTION. Matching start and end keywords keep the code easy to read and maintain.
Q4
C — A function is called inside an expression and does not use CALL. It should be BigRoom ← Area(10, 8). Testing Area() once makes testing easier because all calls use the same code.
Q5
A — A subroutine name cannot contain a space. It should be PrintHeader in Pascal case. Clear names make a program easier to read and maintain.