Past-paper question · 2016 May-June · Paper 21 · Q1(c)(i)

Question 1(c)(i) 2016 · May-June · Paper 21 · 7 marks

Original past-paper question for 1(C)(I)
Original past-paper question for 1(C)(I)
Original past-paper question for 1(C)(I)
Original past-paper question for 1(C)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 1(C)(I)

Official answer for Question 1

Part (c)

(i)

Part (c)

(i)

Example Pascal:

[7]
✓
PROCEDURE PrintNameLine(Symbol : CHAR, Name : STRING,
✓
LabelWidth : INTEGER)
✓
VAR NumberOfSpaces, i : INTEGER;
✓
BEGIN
✓
// remember to allow for symbol at edges
✓
NumberOfSpaces := (LabelWidth – Length(Name) - 2) DIV 2
✓
Write(Symbol);
✓
FOR i := 1 TO NumberOfSpaces DO Write(' ');
✓
WRITE(Name);
✓
IF (LabelWidth - Length(Name)) MOD 2 > 0
✓
THEN NumberOFSpaces := NumberOFSpaces + 1;
✓
FOR i := 1 TO NumberOfSpaces DO Write(' ');
✓
WriteLn(Symbol);
✓
END;
✓
Mark as follows:
  • correct procedure header & ending
  • output symbol at either end of line, and name in middle
  • calculate the number of spaces required
  • output half number of spaces before name
  • output half number of spaces after name
  • check for odd number of spaces
  • add extra space at front/rear

Mark scheme 9691_s16_ms_21.pdf →

Show text version of question

Question 1

Part (c)

(i)

Question 1

Zara wants to write a program to print a set of name labels for a group of students.

Each label will show the name surrounded by a border. There is one gap line above and below the name line. This gap line only has the border symbol at the start and end. There are two spaces between the border symbol and the name.

Here is a label example:

@@@@@@@@@@ @ @ @ FRED @ @ @ @@@@@@@@@@

The user will choose the border symbol for the set of labels.

Zara writes pseudocode for her program:

INPUT Symbol REPEAT INPUT Name LabelWidth ← LENGTH(Name) + 6 CALL PrintTop2Lines(Symbol, LabelWidth) CALL PrintNameLine(Symbol, Name) CALL PrintBottom2Lines(Symbol, LabelWidth) UNTIL Name = "NoName" Zara now decides that the name labels should all be of the same width, regardless of the length of the name.

She amends her top-level design:

CONSTANT LabelWidth = 20 INPUT Symbol REPEAT INPUT Name CALL PrintTop2Lines(Symbol, LabelWidth) CALL PrintNameLine(Symbol, Name, LabelWidth) CALL PrintBottom2Lines(Symbol, LabelWidth) UNTIL Name = "NoName"

The name is to be centred within the label.

(i)

Rewrite the procedure PrintNameLine.

Your solution should allow for the case when the name has an odd number of characters.

Programming language .....................................................................................................

Code ..................................................................................................................................

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[7]

Question 5

Topic relevance

Why this question appears here

71% 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 9691_s16_qp_21.pdf

Keep practising this topic