Past-paper question · 2021 May-June · Paper 22 · Q4(b)

Question 4(b) 2021 · May-June · Paper 22 · 7 marks

Original past-paper question for 4(B)
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 7

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix.
✓
FUNCTION Search(Par1, Par2 : STRING) RETURNS INTEGER
✓
DECLARE Index, RetVal : INTEGER
✓
Index ← 1
✓
RetVal ← -1
✓
WHILE Index <= 100 AND RetVal = -1
✓
IF XRef[Index, 1] = Par1 _
✓
AND (XRef[Index, 2] = Par2 OR XRef[Index, 3] = Par2)
✓
THEN
✓
RetVal ← Index
✓
ENDIF
✓
Index ← Index + 1
✓
ENDWHILE
✓
RETURN RetVal
✓
ENDFUNCTION
✓
Mark as follows:
✓
1 Function heading and ending including parameters
✓
2 Declaration of local variable for array index (Index) but not of global
✓
XRef array
✓
3 Any loop for 100 elements

Question 4

✓
Use of correct XRef 2D array syntax in a loop

Question 5

✓
Logical test of array elements in a loop

Question 6

✓
Exit loop if match found (following attempt at MP5)
✓
Return index number or −1 if not found
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_22.pdf →

Show text version of question

Question 4

Part (b)

Part (b)

A program contains a global 2D array XRef. The array consists of 100 rows and 3 columns.

The array is of data type STRING.

A
function, Search(), takes two parameters Par1 and Par2 as string values and returns an

integer value.

The function returns:

  • the index number of the first row where:
  • the element in column 1 of that row matches Par1 and
  • either of the other two elements in that row match Par2
  • –1 if no match found in any row.

Question 9

Write program code for the function Search().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[7]

Question 10

Topic relevance

Why this question appears here

82% 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_s21_qp_22.pdf

Keep practising this topic