Past-paper question · 2015 October-November · Paper 22 · Q6(b)(ii)

Question 6(b)(ii) 2015 · October-November · Paper 22 · 7 marks

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

Official answer for Question 6

Part (b)

(ii)

(ii)

// main program

✓
INPUT MyString

Question 1

✓
ChangedString ← RemoveSpaces(MyString)
✓
OUTPUT ChangedString

Question 1

✓
// function definition
✓
FUNCTION RemoveSpaces(InputString : STRING)
✓
RETURNS STRING

Question 1

Question 1

✓
DECLARE i
✓
:/AS INTEGER
✓
DECLARE j
✓
:/AS INTEGER
✓
DECLARE NextChar :/AS CHAR

Question 1

✓
DECLARE NewString :/AS STRING
✓
NewString = ""

Question 1

✓
j ← CharacterCount(InputString)
✓
FOR i ← 1 TO j
✓
NextChar ← OneChar(InputString, i)
✓
IF NextChar <> “ “
✓
THEN
✓
// the & character joins together two strings
✓
NewString ← NewString & NextChar
✓
ENDIF
✓
ENDFOR
✓
only awarded if follows

Question 1

Question 1

✓
the previous mark
✓
RETURN
✓
NewString //
✓
RemoveSpaces ← NewString
✓
ENDFUNCTION
✓
[Max 7]

Mark scheme 9608_w15_ms_22.pdf →

Show text version of question

Question 6

Part (b)

(ii)

Question 6

Some pseudocode statements follow which use the following built-in functions:

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR returns the single character at position Position (counting from the start of the string with value 1) from the string ThisString. For example: ONECHAR("Barcelona", 3) returns 'r'.

CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER returns the number of characters in the string ThisString. For example: CHARACTERCOUNT("South Africa") returns 12.

A
program is to be written as follows:
  • the user enters a string
  • the program will form a new string with all <Space> characters removed
  • the new string is output

NewString ""← INPUT InputString

j ← CHARACTERCOUNT(InputString) FOR i ← 1 TO j NextChar ← ONECHAR(InputString, i) IF NextChar <> " " THEN // the & character joins together two strings NewString ← NewString & NextChar ENDIF ENDFOR

OUTPUT NewString

(ii)

An experienced programmer suggests this pseudocode would be best designed as a

function.

Complete the re-design of the pseudocode as follows:

The main program:

  • the user enters MyString
  • the function is called and the changed string is assigned to variable ChangedString

The function:

  • has identifier RemoveSpaces
  • has a single parameter
  • will include the declaration for any local variables used by the function

// main program INPUT MyString ChangedString ← RemoveSpaces(.........................................................................................) OUTPUT ChangedString

// function definition

FUNCTION RemoveSpaces(................................................................) RETURNS ..................

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

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

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

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

j ← CHARACTERCOUNT(InputString) FOR i ← 1 TO j NextChar ← ONECHAR(InputString, i) IF NextChar <> " " THEN // the & character joins together two strings NewString ← NewString & NextChar ENDIF ENDFOR

................................................................................................................................................. ENDFUNCTION

[7]

Question 15

Topic relevance

Why this question appears here

72% assigned-topic match · Programming › Programming basics

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

Keep practising this topic