Past-paper question · 2018 May-June · Paper 22 · Q2(b)

Question 2(b) 2018 · May-June · Paper 22 · 8 marks

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

Official answer for Question 2

Part (b)

Question 8

✓
Feature
✓
Answer
✓
A line number containing an example of an
✓
08 / 09 / 13 / 14 / 15 /
✓
assignment statement

Question 21

✓
A line number containing the start of a ‘pre-

Question 11

✓
condition’ loop
✓
A line number containing the end of a ‘pre-

Question 24

✓
condition’ loop
✓
A line number containing the start of a

Question 17

✓
selection statement
✓
The number of parameters of the LEFT()

Question 2

✓
function
✓
The Boolean operator used
✓
OR
✓
The number of times the function LEFT() is
✓
called from within CountDigits() resulting

Question 6

✓
from the call:
✓
Result ← CountDigits("AB27C4")
✓
The number of local variables

Question 3

Mark scheme 9608_s18_ms_22.pdf →

Show text version of question

Question 2

Part (b)

Question 2

The following is a function design in pseudocode.

Line numbers are given for reference only.

01 FUNCTION CountDigits(InString : STRING) RETURNS CHAR 02 03 DECLARE nc : CHAR 04 DECLARE c : INTEGER 05 DECLARE n : INTEGER 06 07 08 c 0 09 n LENGTH(InString) // get number of characters for loop

Question 10

11 WHILE n > 0 // repeat until no more characters left

Question 12

13 nc LEFT(InString,1) 14 n n - 1 15 InString RIGHT(InString,n) // remove first character

Question 16

17 IF (nc < '0') OR (nc > '9') 18 THEN 19 // do nothing 20 ELSE 21 c c + 1 22 ENDIF

Question 23

24 ENDWHILE

Question 25

26 RETURN c

Question 27

28 ENDFUNCTION

Part (b)

Study the function CountDigits(). Identify the features of the function in the following

table.

Feature Answer

A
line number containing an example of an assignment statement
A
line number containing the start of a ‘pre-condition’ loop
A
line number containing the end of a ‘pre-condition’ loop
A
line number containing the start of a selection statement

The number of parameters passed to the LEFT() function

The Boolean operator used The number of times the function LEFT() is called from within CountDigits() resulting from the call: Result CountDigits("AB27C4") The number of local variables

[8]
Topic relevance

Why this question appears here

71% 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_s18_qp_22.pdf

Keep practising this topic