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. [Figure X.X] Index ErrCode ErrText 1 10 "Invalid identifier name" 2 20 "Bracket mismatch" 3 50 "" 4 60 "Type mismatch in assignment" ... 500 999 <Undefined> Note: • There are less than 500 error codes so corresponding elements in both arrays may be unused. Unused elements in ErrCode have the value 999. These will occur at the end of the array. The value of unused elements in ErrText is undefined. • Values in the ErrCode array are stored in ascending order but not all values may be present. For example, there may be no error code 31. • Some error numbers are undefined. In these instances, the ErrCode array will contain a valid error number but the corresponding ErrText element will contain an empty string. The teacher has defined one program module as follows: Module Description OutputRange() • Prompts for input of two error numbers • Outputs a list of error numbers between the two numbers input (inclusive) together with the corresponding error description • Outputs a warning message when the error description is missing as for error number 50 in the example • Outputs a suitable header and a final count of error numbers found Output based on the example array data above: List of error numbers from 1 to 60 10 : Invalid identifier name 20 : Bracket mismatch 50 : Error Text Missing 60 : Type mismatch in assignment 4 error numbers output
- (a)Write pseudocode for module OutputRange(). Assume that the two numbers input represent a valid error number range.[8]
- (b)(i)Two additional modules are defined: Module Description SortArrays() • Sorts the arrays into ascending order of ErrCode • Takes two parameters: ο an error number as an integer ο an error description as a string AddError() • Writes the error number and error description to the first unused element of the two arrays. Ensures the ErrCode array is still in ascending order • Returns the number of unused elements after the new error number has been added • Returns -1 if the new error number could not be added Write pseudocode for the module AddError(). Assume that the error code is not already in the ErrCode array.[6]
- (b)(ii)A new Module RemoveError() will remove a given error number from the array. Describe the algorithm that would be required. Do not include pseudocode statements in your answer.[3]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- [8] One mark per point (Max 8): 1 Declaration and initialisation of local integer for Count 2 Appropriate prompt and two inputs 3 (Conditional) loop while error number input is in range // error code 999 reached 4 ...and not end of array 5 Check if this ErrCode needs to be output in a loop 6 if so check for blank error text in a loop 7 Output in both cases 8 ....and increment count in a loop 9 OUTPUT of header and summary including count PROCEDURE OutputRange() DECLARE First, Last, Count, Index, ThisErr : INTEGER DECLARE ThisMess : STRING DECLARE PastLast: BOOLEAN Count ← 0 Index ← 1 PastLast ← FALSE OUTPUT "Please input first error number: " INPUT First OUTPUT "Please input last error number: " INPUT Last OUTPUT "List of error numbers from ", First, " to ", Last WHILE Index < 501 AND NOT PastLast ThisErr← ErrCode[Index] IF ThisErr > Last THEN PastLast ← TRUE ELSE IF ThisErr >= First THEN ThisMess ← ErrText[Index] IF ThisMess = "" THEN ThisMess ← "Error Text Missing" ENDIF OUTPUT ThisErr, ": ", ThisMess Count ← Count + 1 ENDIF ENDIF Index ← Index + 1 ENDWHILE OUTPUT Count, " error numbers output" ENDPROCEDURE
- [6] One mark per point: 1 (Conditional) loop terminating when item added OR end of array reached 2 Test for unused element in a loop 3 Assignment of values to arrays // save index of first blank location and assign after loop 4 Set loop termination if empty element found in a loop 5 Call SortArrays() once 6 Calculation of remaining unused elements and return Integer value (for both cases) FUNCTION AddError(ErrNum : INTEGER, ErrMess : STRING) RETURNS INTEGER DECLARE Index, Remaining : INTEGER CONSTANT Unused = 999 Index ← 1 Remaining ← -1 REPEAT IF ErrCode [Index] = Unused THEN ErrCode [Index) ← ErrNum ErrText [Index] ← ErrMess CALL SortArrays() Remaining ← 500 – Index ENDIF Index ← Index + 1 UNTIL Remaining = -1 OR Index > 500 RETURN Remaining ENDFUNCTION
- [3] One mark per point (Max 3): 1. Loop through 500 elements (while error number not found) 2. Compare ErrCode for current element with the error number 3. If same, set element value to 999 (and terminate loop) 4. ... and call SortArrays()(to move 999 to the end) – once only
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →