Amending an algorithm

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

Amending an algorithm

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A program outputs 'Pass' if Mark >= 50. The new requirement says the pass mark is now 60. What should you amend?
A Rewrite the whole program from the start
B Change only the condition to Mark >= 60
2. A loop is FOR Count ← 1 TO 5 and must now read 8 numbers. Which amendment is correct?
A FOR Count ← 1 TO 8
B FOR Count ← 1 TO 5 and add 3 more INPUT lines after the loop
3. An algorithm inputs Length and Width and outputs the area. The new requirement is to also output the perimeter. What kind of amendment is this?
A Adding a new process and a new output
B Changing a loop limit
4. After you amend an algorithm, what should you do last?
A Assume it works because the change was small
B Re-trace it to check the rest still works
5. A program outputs 'Adult' for Age >= 18. The new requirement says to also output 'Senior' when Age >= 65. What should you add?
A A new decision, such as a nested IF or an extra condition
B A new variable declared with DECLARE and nothing else

Match the Pairs

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

Left columnRight column
1IF Mark >= 50 THEN → IF Mark >= 60 THEN AThe student changed the condition but did not check the rest of the algorithm, so the message is now wrong.
2Re-trace with Mark = 60, 59 and 61 BIF Total > 100 THEN OUTPUT "Large" ENDIF
3The new requirement needs one more value from the user, so add a new input. CAmending a condition so the pass mark changes from 50 to 60. Only the limit in this one line changes.
4The new requirement needs a different action for large numbers, so add a decision. DOUTPUT "Enter the bonus" INPUT Bonus
5Pass mark changed from 50 to 60 in the IF line, but OUTPUT still says "Pass is 50 or more" EThe student did not re-trace the amended algorithm, so they missed that the loop still runs the old number of times.
6Amended algorithm was handed in without a trace, so a loop limit of 10 was left in place of the new limit of 20 FRe-checking the amended algorithm with test data to make sure the rest still works.

Definitions

amend an algorithm

Fill in the Blanks

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

1.
// Amended: pass mark is now 60 or more Passed ← Mark __ 60 OUTPUT Passed
2.
// Amended: also ask for the student's age INPUT Name _____ Age
3.
Total ← Price * Quantity // Amended: also show the total ______ Total
4.
IF Total > 100 THEN Total ← Total - 10 _____
5.
// Re-trace: reset the running total first _____ ← 0 Total ← Total + Mark

Spot the Error

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

Question 1
A // Pass mark is now 40
B INPUT Mark
C IF Mark >= 50
D THEN
E OUTPUT "Pass"
F ENDIF
Question 2
A INPUT Mark1
B INPUT Mark2
C INPUT Mark3
D Total ← Mark1 + Mark2
E Mean ← Total / 3
F OUTPUT Mean
Question 3
A // Record 7 days, not 5
B FOR Day ← 1 TO 5
C INPUT Temp
D OUTPUT Temp
E NEXT Day
Question 4
A INPUT Age
B Fare ← 5
C IF Age ← 16
D THEN
E Fare ← 2
F ENDIF
Question 5
A Total ← 0
B Count ← 0
C FOR Num ← 1 TO 5
D Total ← Total + 1
E Count ← Count + 1
F NEXT Num

Answer Key

Amending an algorithm
Section A: Quick Questions
Q1
B — Change only the condition to Mark >= 60
Q2
A — FOR Count ← 1 TO 8
Q3
A — Adding a new process and a new output
Q4
B — Re-trace it to check the rest still works
Q5
A — A new decision, such as a nested IF or an extra condition
Section B: Match the Pairs
Q1
IF Mark >= 50 THEN → IF Mark >= 60 THEN → Amending a condition so the pass mark changes from 50 to 60. Only the limit in this one line changes.
Q2
Re-trace with Mark = 60, 59 and 61 → Re-checking the amended algorithm with test data to make sure the rest still works.
Q3
The new requirement needs one more value from the user, so add a new input. → OUTPUT "Enter the bonus" INPUT Bonus
Q4
The new requirement needs a different action for large numbers, so add a decision. → IF Total > 100 THEN OUTPUT "Large" ENDIF
Q5
Pass mark changed from 50 to 60 in the IF line, but OUTPUT still says "Pass is 50 or more" → The student changed the condition but did not check the rest of the algorithm, so the message is now wrong.
Q6
Amended algorithm was handed in without a trace, so a loop limit of 10 was left in place of the new limit of 20 → The student did not re-trace the amended algorithm, so they missed that the loop still runs the old number of times.
Section C: Definitions
Q1
amend an algorithm — Find the part that must change for the new requirement, change only that part, then re-trace the algorithm to check the rest still works.
Section D: Fill in the Blanks
Q1
// Amended: pass mark is now 60 or more Passed ← Mark >= 60 OUTPUT Passed
Q2
// Amended: also ask for the student's age INPUT Name INPUT Age
Q3
Total ← Price * Quantity // Amended: also show the total OUTPUT Total
Q4
IF Total > 100 THEN Total ← Total - 10 ENDIF
Q5
// Re-trace: reset the running total first Total ← 0 Total ← Total + Mark
Section E: Spot the Error
Q1
C — The requirement changed the pass mark to 40, but the condition still uses the old limit 50. Only this limit should change: IF Mark >= 40.
Q2
D — A third input was added, but the new value Mark3 is not included in the total. The line should be Total ← Mark1 + Mark2 + Mark3 so that dividing by 3 gives the correct mean.
Q3
B — The comment says the algorithm must now cover 7 days, so the loop limit must be changed from 5 to 7: FOR Day ← 1 TO 7.
Q4
C — The new decision for under-16s must be a comparison, not an assignment. ← stores a value; the condition should use the relational operator <: IF Age < 16.
Q5
D — Re-tracing after the amendment shows Total only goes up by 1 each time, giving 5 instead of 15. The total must add the loop value: Total ← Total + Num.