Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms

Q102 · 2210/23/O/N/23 Q5

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.

Q1022210/23/O/N/23original Q5Structured · 9 marks
Question 5 from 2210/23/O/N/23

Worked solution

(a)

Compare each line with what the algorithm should do:

Error 1: line 06 compares Password, which is never input. Correction: use NewPassword, so IF NewPassword = OldList[Posn] [1]

Error 2: line 11 uses AND, so the loop could never end if the password is not found. Correction: change AND to OR (stop when found or when "XXXX" is reached) [1]

Error 3: line 16 uses INPUT to show a message. Correction: change it to OUTPUT [1]

(b)

Draw the corrected algorithm from START to STOP in this order, using the right shapes: rounded boxes for START and STOP, parallelograms for input and output, rectangles for processes and diamonds for decisions.

1. Output "Enter your new password" and input NewPassword (parallelograms). 2. Process box: Posn ← 1, Found ← FALSE. 3. Decision: IS NewPassword = OldList[Posn]? Yes: Found ← TRUE. No: Posn ← Posn + 1. 4. Decision: IS Found = TRUE OR OldList[Posn] = "XXXX"? No: go back to step 3. Yes: carry on. 5. Decision: IS Found = TRUE? Yes: output "Password has been used before". No: output "New password accepted", then process box OldList[Posn] ← NewPassword. 6. Both routes join and go to STOP.

Data entry with a message [1]

Posn and Found set up before the loop [1]

Decision comparing the new password with the list, and Posn and Found updated [1]

Second decision that controls the loop [1]

Also scores toward the four: OldList[Posn] set to NewPassword, and the two outputs.

Correct flowchart symbols used [1]

Arrows in the right direction and Yes/No labels on decisions [1]

KEY IDEAFind errors by checking each line against the purpose, then turn the corrected code into flowchart shapes.
TOTAL 9 marks

Official mark scheme

Mark scheme for 2210/23/O/N/23 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by O/Alevel CS by Wasiq. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.