Past-paper question · 2021 May-June · Paper 23 · Q5(a)

Question 5(a) 2021 · May-June · Paper 23 · 8 marks

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

Official answer for Question 5

Part (a)

Question 8

✓
FUNCTION GroupNum(TelNum, Template : STRING) RETURNS
✓
STRING
✓
DECLARE FString : STRING
✓
DECLARE Index, ThisDigit, ThisGroup : INTEGER
✓
CONSTANT SPACE = ‘ ‘
✓
FString ← ""
✓
ThisDigit ← 1
✓
FOR Index ← 1 TO LENGTH(Template)
✓
ThisGroup ← STRING_TO_NUM(MID(Template, Index, 1))
✓
FString ← FString & MID(TelNum, ThisDigit,
✓
ThisGroup)
✓
FString ← FString & SPACE
✓
ThisDigit ← ThisDigit + ThisGroup
✓
ENDFOR
✓
FString ← FString & RIGHT(TelNum, LENGTH(TelNum) –
✓
ThisDigit)
✓
RETURN FString
✓
ENDFUNCTION
✓
Mark as follows:

Question 1

✓
Function header and end including parameters and RETURN type

Question 2

✓
Local variable declaration and initialisation of FString (return string)

Question 3

✓
Loop to go through each char of Template (each group)

Question 4

✓
Extract character from template in a loop

Question 5

✓
Use of STRING_TO_NUM()on extracted character in a loop

Question 6

✓
Substring statement to pick up current group from TelNum and
✓
concatenate with
✓
FString in a loop

Question 7

✓
Concatenate SPACE separator in a loop
✓
8 Concatenate final characters from TelNum after the loop (+ or – 1
✓
characters)
✓
9 Return the formatted string after reasonable attempt
✓
9608/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_23.pdf →

Show text version of question

Question 5

Part (a)

Question 5

A program stores a contact list of telephone numbers. Each telephone number is stored as a

string of six or more numeric characters.

Before they are displayed, number strings are formatted to make them easier to read. This involves forming the characters into groups, separated by the space character.

The maximum length of a number group is five characters.

Different numbers may have different groupings. A template string is used to define the grouping.

For example:

Number string Template string Formatted string

For the first row, template "53" results in a formatted string comprising:

  • the first five characters in the first group
  • a space character
  • the next three characters in the second group
  • a space character
  • the remaining characters from the number string.

Part (a)

Write pseudocode for a function GroupNum(), which takes a telephone number and a

template as parameter strings and returns a formatted string.

You may assume that the template and telephone number are valid.

Refer to the Appendix on pages 22 and 23 for the list of built-in pseudocode functions and operators.

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

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

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

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

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

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

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

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

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

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

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

Question 13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[8]

Question 14

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Structured programming

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

Keep practising this topic