Past-paper question · 2019 May-June · Paper 23 · Q5(b)(i)

Question 5(b)(i) 2019 · May-June · Paper 23 · 3 marks

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

Official answer for Question 5

Part (b)

(i)

✓
String:

Question 3

  • three possible formats for string containg two words:
✓
"Cat∇∇Dog" // "Cat∇Dog∇" // "∇Cat∇Dog"
✓
Explanation:
  • When a space character is encountered
  • NumWords is incremented by 1
✓
OR:
  • The algorithm counts the spaces
  • and not the words

Mark scheme 9608_s19_ms_23.pdf →

Show text version of question

Question 5

Part (b)

(i)

Question 5

Nigel is learning about string handling. He wants to write code to count the number of words in a

given string. A word is defined as a sequence of alphabetic characters that is separated by one or more space characters.

His first attempt at writing an algorithm in pseudocode is as follows:

PROCEDURE CountWords(Message : STRING)

DECLARE NumWords : INTEGER DECLARE Index : INTEGER CONSTANT Space = ' '

NumWords 0

FOR Index 1 TO LENGTH(Message) IF MID(Message, Index, 1) = Space THEN NumWords NumWords + 1 ENDIF ENDFOR

OUTPUT "Number of words : " , NumWords

ENDPROCEDURE

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

His first attempt is incorrect. He will use white-box testing to help him to identify the problem.

(i)

Write a test string containing two words that gives the output:

Number of words : 2

Use the symbol '∇' to represent each space character in your test string.

Explain why the algorithm gives the output shown above.

String .................................................................................................................................

Explanation .......................................................................................................................

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

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

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

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

[3]
Topic relevance

Why this question appears here

82% assigned-topic match · Hardware › Logic gates and logic circuits

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

Keep practising this topic