Question 7(b) 2022 · October-November · Paper 22 · 8 marks
Reveal official mark-scheme answer
Official answer for Question 7
Part (b)
Question 8
Question 1
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
- Conditional outer loop including flag reset
- Flag set in inner loop to indicate swap
Question 8
Question 9
Show text version of question
Question 7
Part (b)
Question 7
A teacher is designing a program to perform simple syntax checks on programs written by
students.
Two global 1D arrays are used to store the syntax error data. Both arrays contain 500 elements.
- Array ErrCode contains integer values that represent an error number in the range 1 to 800.
- Array ErrText contains string values that represent an error description.
The following diagram shows an example of the arrays.
Index ErrCode ErrText 1 10 "Invalid identifier name" 2 20 "Bracket mismatch" 3 50 "Undeclared variable" 4 60 "Type mismatch in assignment"
…
500 999 <Undefined>
Note:
- There may be less than 500 error numbers so corresponding elements in both arrays may be
- Values in the ErrCode array are stored in ascending order but not all values may be present,
unused. Unused elements in ErrCode have the value 999. The value of unused elements in ErrText is undefined.
for example, there may be no error code 31.
The teacher has defined two program modules as follows:
Module Description
- takes two parameters as integers:
- searches for the error number in the ErrCode array:
○ a line number in the student’s program ○ an error number
OutputError() ○ if found, outputs the corresponding error description and the line number, for example: "Bracket mismatch on line 34" ○ if not found, outputs the line number and a warning, for example: "Unknown error on line 34"
SortArrays() sorts the arrays into ascending order of ErrCode
Question 17
Part (b)
Write an efficient bubble sort algorithm in pseudocode for module SortArrays().
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Question 19
Why this question appears here
92% assigned-topic match · Algorithm design and problem-solving › Algorithms
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9618_w22_qp_22.pdf
