Past-paper question · 2018 October-November · Paper 23 · Q4(b)

Question 4(b) 2018 · October-November · Paper 23 · 8 marks

Original past-paper question for 4(B)
Original past-paper question for 4(B)
Reveal official mark-scheme answer Official mark-scheme answer for 4(B)

Official answer for Question 4

Part (b)

✓
‘Pseudocode’ solution included here for development and clarification of

Question 8

✓
mark scheme.
✓
Programming language solutions appear at the end of this mark scheme.
✓
FUNCTION Update(NewData: STRING) RETURNS INTEGER
✓
DECLARE ArrayIndex : INTEGER
✓
DECLARE Found : BOOLEAN
✓
DECLARE Validate : BOOLEAN
✓
ArrayIndex ← 1
✓
Found ← FALSE
✓
WHILE ArrayIndex <= LastElement AND Found = FALSE
✓
IF ThisArray[ArrayIndex, 1] > NewData
✓
THEN
✓
Found ← TRUE
✓
ELSE
✓
ArrayIndex ← ArrayIndex + 1
✓
ENDIF
✓
ENDWHILE
✓
IF Found = TRUE
✓
THEN
✓
Validate ← Insert(ArrayIndex, NewData)
✓
IF Validate = FALSE
✓
THEN
✓
ArrayIndex ← -1
✓
ENDIF
✓
ELSE
✓
ArrayIndex ← 0
✓
ENDIF
✓
RETURN ArrayIndex
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Function heading and ending including parameters

Question 2

✓
Local variable declarations and Initialisation of ArrayIndex and Found

Question 3

✓
WHILE loop

Question 4

✓
First IF–THEN–ELSE–ENDIF clause

Question 5

✓
Second IF clause including function call to Insert()

Question 6

✓
Check Return value

Question 7

✓
Set / return –1 IF (Validate) FALSE

Question 8

✓
Return parameter value (–1 or 0 // ArrayIndex)
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2018
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_w18_ms_23.pdf →

Show text version of question

Question 4

Part (b)

Question 4

Part of a program written in pseudocode is shown.

010 DECLARE ThisArray : ARRAY [1:100, 1:10] OF STRING 011 DECLARE LastElement : INTEGER

… 100 FUNCTION Update(NewData : STRING) RETURNS INTEGER 101 DECLARE ArrayIndex : INTEGER 102 DECLARE Found : BOOLEAN 103 104 ArrayIndex 1 105 Found FALSE 106 107 WHILE ArrayIndex <= LastElement AND Found = FALSE 108 IF ThisArray[ArrayIndex, 1] > NewData 109 THEN 110 Found TRUE 111 ELSE 112 ArrayIndex ArrayIndex + 1 113 ENDIF 114 ENDWHILE 115 116 IF Found = TRUE 117 THEN 118 CALL Insert(ArrayIndex, NewData) 119 ELSE 120 ArrayIndex 0 121 ENDIF 122 123 RETURN ArrayIndex 124 ENDFUNCTION

Part (b)

Line 118 of the function Update() calls the subroutine Insert(). A designer decides to

convert Insert() from a procedure to a function. Insert() returns TRUE or FALSE.

A
programmer must amend the function Update() as follows:
  • If Insert() returns FALSE then the function Update() returns -1
  • If Insert() returns TRUE then the function Update() returns the value as before.

Write program code to implement the amended Update() function.

Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type.

Programming language .............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[8]

Question 12

Topic relevance

Why this question appears here

91% assigned-topic match · Programming › Structured programming

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_w18_qp_23.pdf

Keep practising this topic