2210/22/M/J/20 question 3: worked solution (May/June 2020, paper 22)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 7.8 Identifying and correcting errors in algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8. Q66 2210/22/M/J/20 original Q3 Structured · 10 marks Worked solution (a) Compare each line with what the algorithm should do. Error 1: line 01 . Correction: HighestMark ← 0 (it must start low, not at 100) [1] Error 2: line 07 . Correction: INPUT Mark[Count] (the index is Count, not Counter) [1] Error 3: line 10 . Correction: HighestMarkStudents ← HighestMarkStudents + 1 (add 1, not take away) [1] Error 4: line 14 . Correction: HighestMark ← Mark[Count] (the new highest mark is stored in HighestMark) [1] (b) Add a lowest-mark version of the highest-mark code. LowestMark ← 100 LowestMarkStudents ← 0 FOR Count ← 1 TO 35 IF Mark[Count] = LowestMark THEN LowestMarkStudents ← LowestMarkStudents + 1 ENDIF IF Mark[Count] < LowestMark THEN LowestMarkStudents ← 1 LowestMark ← Mark[Count] ENDIF NEXT Count OUTPUT "There are ", LowestMarkStudents, " with the lowest mark of ", LowestMark Add a variable LowestMark [1] Set it to a high value, for example 100 [1] Add a variable LowestMarkStudents [1] Set it to zero [1] Check if Mark[Count] = LowestMark and, if true, add 1 to LowestMarkStudents [1] Check if Mark[Count] < LowestMark and, if true, set LowestMarkStudents to 1 and LowestMark to Mark[Count]. Add an extra output statement for both values. [1] KEY IDEA Track the best value and how many students share it; a new best value resets the count to 1. TOTAL 10 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.