Past-paper question · 2017 October-November · Paper 21 · Q5(b)

Question 5(b) 2017 · October-November · Paper 21 · 6 marks

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

Official answer for Question 5

Part (b)

✓
Invalid string examples:

Question 6

✓
A string with nothing before ‘@’
✓
A string with nothing after ‘@’
✓
A string with 1 or 2 characters after ‘@’
✓
A string with no ‘@’symbol
✓
A string with more than one ‘@’ symbol
✓
Explanation
✓
Sensible explanation mapping each given string to an individual rule
✓
One mark for string
✓
One mark for explanation
✓
Each rule should be tested once only
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2017
✓
Programming Example Solutions
✓
Q3(b): Visual Basic
✓
Sub FindRepeats()
✓
Dim Repeats As Integer
✓
Dim i As Integer
✓
Dim FirstID As String
✓
Dim SecondID As String
✓
Repeats = 0
✓
For i = 1 To 99
✓
FirstID = Left(UserNameArray(i), 6)
✓
SecondID = Left(UserNameArray(i + 1), 6)
✓
If FirstID = SecondID Then
✓
Console.WriteLine(UserNameArray(i + 1))
✓
Repeats = Repeats + 1
✓
End If
✓
Next i
✓
If Repeats = 0 Then
✓
Console.WriteLine(“The array contains no repeated UserIDs")
✓
Else
✓
Console.WriteLine(“There are “ & Repeats & " repeated UserIDs")
✓
End If
✓
End Sub
✓
Alternative:
✓
Sub FindRepeats ()
✓
Dim RepeatCount, i As Integer
✓
Dim FirstID, SecondID As String
✓
RepeatCount = 0
✓
For i = 1 to 99
✓
FirstID = Left(UserNameArray(i-1),6)
✓
SecondID = Left(UserNameArray(i),6)
✓
If FirstID = SecondID then
✓
Console.WriteLine (UserNameArray(i))
✓
RepeatCount = RepeatCount + 1
✓
End If
✓
Next i
✓
If RepeatCount = 0 then
✓
Console.WriteLine ("The array contains no repeated UserIDs")
✓
Else
✓
Console.WriteLine ("There are "& RepeatCount & " repeated UserIDs")
✓
End If
✓
End Sub
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2017
✓
Q3(b): Pascal
✓
procedure FindRepeats ();
✓
var
✓
RepeatCount, i : integer;
✓
FirstID, SecondID : string;
✓
begin
✓
RepeatCount := 0;
✓
for i := 1 to 99 do
✓
begin
✓
FirstID := Copy(UserNameArray[i-1],1,6);
✓
SecondID := Copy(UserNameArray[i],1,6);
✓
if FirstID = SecondID then
✓
begin
✓
writeln (UserNameArray[i]);
✓
RepeatCount := RepeatCount + 1;
✓
end;
✓
end;
✓
if RepeatCount = 0 then
✓
writeln ('The array contains no repeated UserIDs')
✓
else
✓
writeln ('There are ', RepeatCount,' repeated UserIDs')
✓
end;
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2017
✓
Q3(b): Python
✓
def FindRepeats():
✓
#Repeats, i Integer
✓
#FirstID, SecondID string
✓
Repeats = 0
✓
for i in range(0, len(UserNameArray)-1):
✓
FirstID = (UserNameArray[i])[:6]
✓
SecondID = (UserNameArray[i+1])[:6]
✓
if FirstID == SecondID:
✓
print(UserNameArray[i+1])
✓
Repeats = Repeats + 1
✓
if Repeats == 0:
✓
print("The array contains no repeated UserIDs")
✓
else:
✓
print(“There are “, Repeats, " repeated UserIDs")
✓
Alternative:
✓
def FindRepeats ():
✓
RepeatCount = 0
✓
## Defined as an integer
✓
for i in range (1,100):
✓
## depending on next two
✓
lines(0,99) (2,101)
✓
FirstID = UserNameArray[i-1]
✓
## Defined as string
✓
SecondID = UserNameArray[i]
✓
## Defined as string
✓
if FirstID[0:6] == SecondID[0:6]:
✓
## Using split
✓
print (UserNameArray[i])
✓
RepeatCount += 1
✓
if repeatCount == 0:
✓
print ('The array contains no repeated UserIDs')
✓
else:
✓
print ('There are ', RepeatCount,' repeated UserIDs')

Mark scheme 9608_w17_ms_21.pdf →

Show text version of question

Question 5

Part (b)

Question 5

A sports club maintains a record of the email address of each of its members. The details are

stored in a text file, EmailDetails.txt. The format of each line of the text file is as follows:

<MembershipNumber><EmailAddress>

  • MembershipNumber is a four-character string of numerals.
  • EmailAddress is a variable-length string.

Membership of the club has increased and a four-character membership number is no longer adequate.

A
procedure, MakeNewFile, is required to perform the following actions:

1. Create a new file, NewEmailDetails.txt 2. Read a line from file EmailDetails.txt 3. Extend MembershipNumber by adding two leading zero digits (for example, "1234" becomes "001234") 4. Write the new line to file NewEmailDetails.txt 5. Repeat steps 2 to 4 for all lines in the original file.

Part (b)

A function, IsEmailValid, is to be written to test for a valid email address format.

An email address has a valid format if it obeys the following three rules:

1. It contains a single ‘@’ symbol. 2. The ‘@’ symbol must be preceded by at least one character. 3. The ‘@’ symbol must be followed by at least three characters.

Choose three different invalid strings to test distinct aspects of the rules.

Explain your choice in each case.

1 ................................................................................................................................................

Explanation ...............................................................................................................................

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

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

2 ................................................................................................................................................

Explanation ...............................................................................................................................

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

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

3 ................................................................................................................................................

Explanation ...............................................................................................................................

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

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

[6]

Question 14

Appendix Built-in functions (pseudocode) In each function, if the function call is not properly formed, the function returns an error.

MODULUS(x : INTEGER, y : INTEGER) RETURNS INTEGER

returns the remainder when x is divided by y using integer arithmetic. Example: MODULUS(5, 2) returns 1

INT(x : REAL) RETURNS INTEGER

returns the integer part of x. Example: INT(27.5415) returns 27

LENGTH(ThisString : STRING) RETURNS INTEGER

returns the integer value representing the length of string ThisString. Example: LENGTH("Happy Days") returns 10

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING

returns leftmost x characters from ThisString. Example: LEFT("ABCDEFGH", 3) returns string "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING

returns rightmost x characters from ThisString. Example: RIGHT("ABCDEFGH", 3) returns string "FGH"

Operators (pseudocode)

Operator Description Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE

Question 15

Question 16

reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.

Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

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 9608_w17_qp_21.pdf

Keep practising this topic