2210/22/M/J/21 question 4: worked solution (May/June 2021, paper 22)
Show as plain textHide 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. Q90 2210/22/M/J/21 original Q4 Structured · 7 marks Worked solution (a) Run the algorithm one input at a time. A password shorter than 8 characters is rejected at once. A password of 8 or more characters is followed by a second input, which is compared with the first. Secret has 6 characters, so it is rejected without asking for a repeat. VerySecret and Pa55word each have 8 or more characters and match their repeat, so they are accepted. 999 has fewer than 8 characters, so Reject is output, then the loop stops. Password PasswordRepeat OUTPUT Please enter password Secret Reject Please enter password Secret Reject Please enter password VerySecret VerySecret Accept Please enter password Pa55word Pa55word Accept Please enter password 999 Reject Password column correct [1] PasswordRepeat column correct [1] OUTPUT column correct [1] (b) Add a counter for the number of tries and put a loop around the part that asks for the repeat password. Add a counter (or a flag) before the first INPUT, and set it to 0 at the start [1] After IF Length(Password) >= 8 THEN (or after INPUT PasswordRepeat), start a REPEAT or WHILE loop so the password can be checked again [1] After OUTPUT "Reject", add 1 to the counter , output a message such as "Try again" and add INPUT PasswordRepeat again [1] After the ENDIF, end the loop with UNTIL (or ENDWHILE) so it stops after three tries or when the repeated password matches the first one [1] Also accepted: after OUTPUT "Accept", reset the flag to show the passwords matched. KEY IDEA Count the tries with a counter and wrap a loop round the check so it repeats until it matches or the counter reaches 3. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.