Past-paper question · 2019 May-June · Paper 21 · Q4(b)

Question 4(b) 2019 · May-June · Paper 21 · 4 marks

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

✓
DECLARE Code : ARRAY[1:500, 1:4] OF STRING

Question 4

✓
DECLARE RowIndex : INTEGER
✓
DECLARE ColIndex : INTEGER
✓
FOR RowIndex ← 1 TO 500
✓
FOR ColIndex ← 1 TO 4
✓
Code[RowIndex, ColIndex] ← "Empty"
✓
ENDFOR
✓
ENDFOR
✓
One mark for each of the following:

Question 1

✓
Array declaration

Question 2

✓
Additional local variable

Question 3

✓
Nested loops

Question 4

✓
Array element assignment within the inner loop
✓
RowIndex and ColIndex can be interchangeable

Mark scheme 9608_s19_ms_21.pdf →

Show text version of question

Question 4

Part (b)

Question 4

The following pseudocode is a string handling function.

For the built-in functions list, refer to the Appendix on page 16.

FUNCTION Clean(InString : STRING) RETURNS STRING

DECLARE NewString : STRING DECLARE Index : INTEGER DECLARE AfterSpace : BOOLEAN DECLARE NextChar : CHAR CONSTANT Space = ' '

AfterSpace FALSE NewString ""

FOR Index 1 TO LENGTH(InString) NextChar MID(InString, Index, 1) IF AfterSpace = TRUE THEN IF NextChar <> Space THEN NewString NewString & NextChar AfterSpace FALSE ENDIF ELSE NewString NewString & NextChar IF NextChar = Space THEN AfterSpace TRUE ENDIF ENDIF ENDFOR

RETURN NewString

ENDFUNCTION

Question 9

Part (b)

The following pseudocode declares and initialises an array.

DECLARE Code : ARRAY[1:100] OF STRING DECLARE Index : INTEGER

FOR Index 1 TO 100 Code[Index] "" ENDFOR

The design of the program is changed as follows:

  • the array needs to be two dimensional, with 500 rows and 4 columns
  • the elements of the array need to be initialised to the string "Empty"

Re-write the pseudocode to implement the new design.

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

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

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

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

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

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

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

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

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

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

[4]
Topic relevance

Why this question appears here

91% 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_s19_qp_21.pdf

Keep practising this topic