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

Question 4(b)(ii) 2021 · May-June · Paper 23 · 1 mark

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

Official answer for Question 4

Part (b)

(ii)

✓
•
✓
Change RETURN Result to RETURN Count

Question 1

✓
•
✓
Change final if to IF Count < 3 and Result <> -1
✓
•
✓
Terminate the loop as soon as an illegal character is encountered

Mark scheme 9608_s21_ms_23.pdf →

Show text version of question

Question 4

Part (b)

(ii)

Question 4

Study the following pseudocode for a string handling function Check().

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

FUNCTION Check(InString : STRING) RETURNS INTEGER

DECLARE Index, Result, Count : INTEGER DECLARE NextChar : CHAR

Result 0 Count 1

FOR Index 1 TO LENGTH(InString)

NextChar MID(InString, Index, 1) IF (NextChar >= '0' AND NextChar <= '9') OR NextChar = '.' THEN Result Result + 1 ELSE IF NextChar = ',' THEN Count Count + 1 ELSE Result -1 ENDIF ENDIF ENDFOR

IF Count < 3 THEN RETURN -1 ELSE RETURN Result ENDIF

ENDFUNCTION

Question 9

A
number group is a string of characters that represents an integer or decimal value. A comma

separates number groups.

For example, "74.0" is a number group in the string "74.0,4.6,3x2".

The function Check() is intended to analyse the number groups in the parameter passed.

The function returns:

  • a count of the number groups in the parameter passed

or

  • −1 if there are less than three number groups in the string or if any non-numeric

characters occur in the string (other than decimal point and comma).

There is an error in the algorithm causing an incorrect value to be returned by the function.

(ii)

Describe how the algorithm could be amended to correct the error.

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

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

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

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

[1]
Topic relevance

Why this question appears here

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

Keep practising this topic