Question 3 2017 · October-November · Paper 22 · 8 marks
Reveal official mark-scheme answer
Official answer for Question 3
- "SortArray"
Show text version of question
Question 3
shop. There are 100 elements in the array. Each element stores one data item.
The format of each data item is as follows:
<ProductID><ProductName>
- ProductID is a four-character string of numerals
- ProductName is a variable-length string
The following pseudocode is an initial attempt at defining a procedure, ArraySort, which will perform a bubble sort on Product. The array is to be sorted in ascending order of ProductID. Line numbers have been added for identification purposes only.
01 PROCEDURE SortArray 02 DECLARE Temp : CHAR 03 DECLARE FirstID, SecondID : INTEGER 04 FOR I 1 TO 100 05 FOR J 2 TO 99 06 FirstID MODULUS(LEFT(Product[J], 6)) 07 SecondID MODULUS(LEFT(Product[J + 1], 6)) 08 IF FirstID > SecondID 09 THEN 10 Temp Product[I] 11 Product[I] Product[J + 1] 12 Product[J + 1] Temp 13 ENDFOR 14 ENDIF 15 ENDFOR 16 ENDPROCEDURE
Question 9
The pseudocode on page 8 contains a number of errors. Complete the following table to show:
- the line number of the error
- the error itself
- the correction that is required.
Note:
- If the same error occurs on more than one line, you should only refer to it ONCE.
- Lack of optimisation should not be regarded as an error.
Line Error Correction number
01 Wrong procedure name – “SortArray” PROCEDURE ArraySort
Question 10
Why this question appears here
82% assigned-topic match · Data types and structures › Data types and records
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 9608_w17_qp_22.pdf
