Past-paper question · 2024 October-November · Paper 41 · Q1(c)

Question 1(c) 2024 · October-November · Paper 41 · 4 marks

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

Official answer for Question 1

Part (c)

Question 1

mark each

Question 4

  • Function header (and close where appropriate) taking (min) two parameters and returns a value in all cases
  • Looping through each character in each string parameter …
  • … return 1 when first parameter second
  • … return 2 when first parameter second
✓
e.g.
✓
Python
✓
def CompareStrings(First,
✓
Second):
✓
Count = 0
✓
while True:
✓
if First[Count] <
✓
Second[Count]:
✓
return 1
✓
elif First[Count]
✓
> Second[Count]:
✓
return 2
✓
else:
✓
Count = Count
✓
+ 1
✓
VB.NET
✓
Function CompareStrings(FirstS, SecondS)
✓
Dim Count As Integer = 1
✓
While (True)
✓
If Mid(FirstS, Count, 1) < Mid(SecondS, Count, 1) Then
✓
Return 1
✓
ElseIf Mid(FirstS, Count, 1) > Mid(SecondS, Count, 1) Then
✓
Return 2
✓
Else
✓
Count = Count + 1
✓
End If
✓
End While
✓
End Function
✓
Cambridge International AS & A Level – Mark Scheme
✓
9618/41
✓
October/November 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_w24_ms_41.pdf →

Show text version of question

Question 1

Part (c)

Question 1

A program sorts string data using different sorting methods.

Part (c)

The function CompareStrings():

  • takes two strings as parameters
  • compares each string, one character at a time, to identify which string comes first

alphabetically. If the first two characters are the same, the second character of each string is compared. This continues until the two characters are different.

The function:

  • returns 1 if the first parameter comes before the second alphabetically
  • returns 2 if the second parameter comes before the first alphabetically.

Write program code for CompareStrings().

Assume that all strings are in lower case.

Assume that a difference between two strings will always be identified before the end of one string is reached.

Do not use an in-built string comparison function.

The strings must be compared one character at a time.

Save your program.

Copy and paste the program code into part 1(c) in the evidence document.

[4]

Question 5

Topic relevance

Why this question appears here

82% 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 9618_w24_qp_41.pdf

Keep practising this topic