Question 5(b)(ii) 2019 · May-June · Paper 23 · 6 marks
Reveal official mark-scheme answer
Official answer for Question 5
Part (b)
(ii)
Question 6
- Output: Number of words : 2
- Check character at end of string
- If not a character, increment variable NumTotal
- Add a space at the beginning / end of string
- At the start of the algorithm
- Change Initialisation of NumWords
- After the loop
- Add 1 to NumWords
- Output: Number of words : 5
- Detect a space followed by a space
- Count as a single space / only increment variable NumTotal once
- Replace all double spaces with a single space
- Before the loop
- After the loop
- Subtract 2 from NumWords
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 ........................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Question 14
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
