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

Question 5(b)(ii) 2019 · May-June · Paper 23 · 6 marks

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

Official answer for Question 5

Part (b)

(ii)

✓
String 1:

Question 6

  • Output: Number of words : 2
✓
Description 1:
  • Check character at end of string
  • If not a character, increment variable NumTotal
✓
OR:
  • Add a space at the beginning / end of string
  • At the start of the algorithm
✓
OR:
  • Change Initialisation of NumWords
✓
•
✓
to 1
✓
OR:
  • After the loop
  • Add 1 to NumWords
✓
String 2:
  • Output: Number of words : 5
✓
Description 2:
  • Detect a space followed by a space
  • Count as a single space / only increment variable NumTotal once
✓
OR:
  • Replace all double spaces with a single space
  • Before the loop
✓
OR:
  • After the loop
  • Subtract 2 from NumWords
✓
Many possible solutions.
✓
One mark for each correct output
✓
One marks for each description bullet point
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s19_ms_23.pdf →

Show text version of question

Question 5

Part (b)

(ii)

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.

(ii)

Nigel tested the procedure with the strings:

String 1: "Red∇and∇Yellow" String 2: "Green∇∇and∇∇Pink∇"

Give the output that is produced for each of the strings.

Describe the changes that would need to be made to the algorithm to give the correct output in each case.

Do not write pseudocode or program code.

String 1 ..............................................................................................................................

Description ........................................................................................................................

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

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

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

String 2 ..............................................................................................................................

Description ........................................................................................................................

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

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

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

[6]

Question 14

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