Past-paper question · 2021 May-June · Paper 21 · Q4(a)

Question 4(a) 2021 · May-June · Paper 21 · 6 marks

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

Official answer for Question 4

Part (a)

✓
'Pseudocode' solution included here for development and clarification of mark scheme.

Question 6

✓
Programming language solutions appear in the Appendix.
✓
PROCEDURE ScanArray(SearchString STRING)
✓
DECLARE Index, Total : INTEGER
✓
DECLARE Error : BOOLEAN
✓
Index ← 1
✓
Total ← 0
✓
Error ← FALSE
✓
WHILE Index <= 1000 AND Error <> TRUE
✓
IF LENGTH(ThisArray[Index]) > 5
✓
THEN
✓
IF LEFT(ThisArray[Index], 4) = SearchString
✓
THEN
✓
Total ← Total + LENGTH(ThisArray[Index]) - 5
✓
ENDIF
✓
Index ← Index + 1
✓
ELSE
✓
Error ← TRUE
✓
ENDIF
✓
ENDWHILE
✓
IF Index > 1
✓
THEN
✓
ArrayResult ← INT(Total / (Index - 1))
✓
ENDIF
✓
ENDPROCEDURE
✓
Mark as follows:

Mark scheme 9608_s21_ms_21.pdf →

Show text version of question

Question 4

Part (a)

Question 4

The following is part of a program written in pseudocode:

DECLARE ThisArray : ARRAY[1:1000] OF STRING DECLARE ArrayResult : INTEGER

PROCEDURE ScanArray(SearchString : STRING)

DECLARE Index, Total : INTEGER DECLARE Error : BOOLEAN

Index 1 Total 0 Error FALSE

WHILE Index <= 1000 AND Error <> TRUE IF LENGTH(ThisArray[Index]) > 5 THEN IF ThisArray[Index] = SearchString THEN Total Total + LENGTH(ThisArray[Index]) ENDIF Index Index + 1 ELSE Error TRUE ENDIF ENDWHILE

ArrayResult INT(Total / (Index - 1))

ENDPROCEDURE

The procedure ScanArray() is amended as follows:

  • SearchString is compared with just the first four characters of each array element.
  • The total ignores the first five characters of each array element.
  • When calculating ArrayResult, prevent any possible division by zero.

Refer to the Appendix on pages 22–23 for the list of built-in pseudocode functions and operators.

Question 11

Part (a)

Write program code to implement this amended procedure ScanArray().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[6]

Question 12

Topic relevance

Why this question appears here

72% 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_s21_qp_21.pdf

Keep practising this topic