Past-paper question · 2024 May-June · Paper 21 · Q8(a)

Question 8(a) 2024 · May-June · Paper 21 · 6 marks

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

Official answer for Question 8

Part (a)

✓
FUNCTION DeleteComment(Line : STRING) RETURNS STRING

Question 8

✓
DECLARE NewLine, TwoChars : STRING
✓
DECLARE Count, TrimTo : INTEGER
✓
CONSTANT Comment = "//"
✓
NewLine Line
✓
TrimTo 0
✓
Count 1
✓
WHILE Count < LENGTH(Line) AND TrimTo = 0
✓
TwoChars MID(Line, Count, 2) // extract 2 chars
✓
IF TwoChars = Comment THEN
✓
TrimTo Count
✓
ENDIF
✓
Count Count + 1
✓
ENDWHILE
✓
IF TrimTo <> 0 THEN
✓
NewLine LEFT(Line, TrimTo - 1)
✓
ENDIF
✓
RETURN NewLine
✓
ENDFUNCTION
✓
Mark as follows:

Question 1

✓
Loop to length of Line (parameter) // length of Line -1

Question 2

✓
Terminate loop on first double slash

Question 3

✓
Attempt to extract one/two characters in a loop

Question 4

✓
Check for "//" after attempt at extraction in a loop

Question 5

✓
Record start position of comment // Calculate amount of trim required

Question 6

✓
Attempt to trim Line from start of comment

Question 7

✓
Completely correct trimmed Line from start of comment

Question 8

✓
Return Line after a reasonable overall attempt
✓
9618/21
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s24_ms_21.pdf →

Show text version of question

Question 8

Part (a)

Question 8

Question 7

P2 6 (x2, y2) 5 B

Question 4

Question 3

P1 2 (x1, y1)

Question 1

x

The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6).

The value B2 is given by the formula:

B2 = (x1 − x2)2 + (y1 − y2)2

In this example:

B2 = (3 − 6)2 + (2 − 6)2 B2 = (–3)2 + (–4)2 B2 = 9 + 16 B2 = 25

Question 13

Part (a)

A function IsRA() will:

  • take three sets of integers as parameters representing the coordinates of the three
  • endpoints that form a triangle

  • return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE.

In pseudocode, the operator ‘^’ represents an exponent, which is the number of times a value is multiplied by itself. For example, the expression Value2 may be written in pseudocode as Value ^ 2

Complete the pseudocode for the function IsRA().

FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ENDFUNCTION

[6]

Question 14

Topic relevance

Why this question appears here

91% assigned-topic match · Data types and structures › Data types and records

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 9618_s24_qp_21.pdf

Keep practising this topic