2210/23/O/N/23 question 5: worked solution (October/November 2023, paper 23)

Show as plain text

Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8. Q102 2210/23/O/N/23 original Q5 Structured · 9 marks 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 IDEA Find errors by checking each line against the purpose, then turn the corrected code into flowchart shapes. TOTAL 9 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by O/Alevel CS by Wasiq. Tap the picture to open it on YouTube.