Past-paper question · 2017 May-June · Paper 23 · Q3

Question 3 2017 · May-June · Paper 23 · 11 marks

Original past-paper question for 3
Reveal official mark-scheme answer Official mark-scheme answer for 3

Official answer for Question 3

Question 11

✓
FUNCTION StringClean(Instring STRING) RETURNS STRING
✓
DECLARE NextChar : CHAR
✓
DECLARE OutString : STRING
✓
OutString ← ""
✓
// initialise the return string
✓
// loop through Instring to produce OutString
✓
FOR n ← 1 TO LENGTH(InString)
✓
// from first to last
✓
NextChar ← MID(Instring, n, 1) //get next
✓
character and
✓
NextChar ← LCASE(NextChar) //convert to lower
✓
case
✓
IF NextChar >= 'a' AND NextChar <= 'z' //check if
✓
alphabetic
✓
THEN
✓
OutString ← OutString & NextChar //add to
✓
OutString
✓
ENDIF
✓
ENDFOR
✓
RETURN OutString
✓
// return value
✓
ENDFUNCTION
✓
One mark per underlined word / expression
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_23.pdf →

Show text version of question

Question 3

A
string conversion function, StringClean, is to be written.

This function will form a new string, OutString, from a given string, InString, by:

  • removing all non-alphabetic characters
  • converting all alphabetic characters to lower case.

For example:

InString = "Good Morning, Dave" OutString = "goodmorningdave"

The first attempt at writing the pseudocode for this function is shown below.

Complete the pseudocode using relevant built-in functions.

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

FUNCTION StringClean(...........................) RETURNS ..........

DECLARE NextChar : ......................................

DECLARE ................................................ : STRING

..................................... //initialise the return string

//loop through InString to produce OutString

FOR n 1 TO .............................. //from first to last

NextChar ............................. //get next character and

NextChar ............................. //convert to lower case

IF ........................................ //check if alphabetic

THEN

........................................ //add to OutString

ENDIF

ENDFOR

............................................//return value

ENDFUNCTION

[11]

Question 7

Topic relevance

Why this question appears here

92% assigned-topic match · Programming › Constructs

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

Keep practising this topic