Question 4(a)(iii) 2016 · October-November · Paper 42 · 2 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (a)
(iii)
(iii)
1 mark for identifying the correct line, 1 mark for writing the corrected line
Show text version of question
Question 4
Part (a)
(iii)
Question 4
Circle the programming language that you have studied:
Visual Basic (console mode) Python Pascal Delphi (console mode)
(iii)
The table shows a module definition for BubbleSort in three programming languages.
Study one of the examples. Indicate your choice by circling A, B or C:
A) Python 01 def BubbleSort(SList, Max): 02 NoMoreSwaps = False 03 while NoMoreSwaps == False: 04 NoMoreSwaps = True 05 for i in (Max - 1): 06 if SList[i] > SList[i + 1]: 07 NoMoreSwaps = True 08 Temp = SList[i] 09 SList[i] = SList[i + 1] 10 SList[i + 1] = Temp B) Pascal/Delphi 01 PROCEDURE BubbleSort(VAR SList : ARRAY OF INTEGER; Max : INTEGER); 02 VAR NoMoreSwaps : BOOLEAN; i, Temp : INTEGER; 03 BEGIN 04 REPEAT 05 NoMoreSwaps := TRUE; 06 FOR i := 1 TO (Max – 1) 07 IF SList[i] > SList[i + 1] 08 THEN 09 BEGIN 10 NoMoreSwaps := TRUE; 11 Temp := SList[i]; 12 SList[i] := SList[i + 1]; 13 SList[i + 1] := Temp; 14 END; 15 UNTIL NoMoreSwaps; 16 END; C) Visual Basic 01 Sub BubbleSort(ByRef SList() As Integer, ByVal Max As Integer) 02 Dim NoMoreSwaps As Boolean, i, Temp As Integer 03 Do 04 NoMoreSwaps = True 05 For i : 0 To (Max – 1) 06 If SList(i) > SList(i + 1) Then 07 NoMoreSwaps = True 08 Temp = SList(i) 09 SList(i) = SList(i + 1) 10 SList(i + 1) = Temp 11 End If 12 Next 13 Loop Until (NoMoreSwaps = True) 14 End Sub
Question 17
The programming environment reported a syntax error in the BubbleSort code.
State the line number ........................................................................................................................
Write the correct code for this line.
...............................................................................................................................................[2]
Why this question appears here
99% assigned-topic match · Programming › Constructs
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_w16_qp_42.pdf
