Past-paper question · 2019 October-November · Paper 21 · Q6(d)(ii)

Question 6(d)(ii) 2019 · October-November · Paper 21 · 2 marks

Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Original past-paper question for 6(D)(II)
Reveal official mark-scheme answer Official mark-scheme answer for 6(D)(II)

Official answer for Question 6

Part (d)

(ii)

✓
'Pseudocode' solution included here for development and clarification of mark

Question 2

✓
scheme.
✓
Programming language example solutions appear in the Appendix.
✓
CALL ClearArray(Duplicates, 100, "Empty")
✓
Mark as follows:
✓
•
✓
Procedure call
✓
•
✓
Parameter list (in brackets)
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2019
✓
Program Code Example Solutions
✓
Question 6(b): Visual Basic
✓
Function SearchFileNtoZ(ByVal SearchString As String) As Boolean
✓
Dim FileData As String
✓
Dim Found As Boolean
✓
Found = FALSE
✓
FileOpen(1, "UserListNtoZ.txt", OpenMode.Input)
✓
While Not EOF(1) And Not Found
✓
Filedata = LineInput(1)
✓
If SearchString & ' * ' = Left(FileData, Len(SearchString)+1) Then
✓
Found = TRUE
✓
End If
✓
End While
✓
FileClose(1)
✓
Return Found
✓
End Function
✓
Question 6(b): Pascal
✓
function SearchFileNtoZ (SearchString : string): boolean;
✓
var
✓
FileData : string;
✓
Found : boolean;
✓
MyFile : text;
✓
begin
✓
Found := FALSE;
✓
assign(MyFile, "UserListNtoZ.txt");
✓
reset (Myfile);
✓
while Not EOF(MyFile) And Not Found do
✓
begin
✓
readLn(MyFile, FileData);
✓
if SearchString + ' * ' = LeftStr(FileData, length(SearchString)+1)
✓
then
✓
Found := TRUE;
✓
end;
✓
close(MyFile);
✓
result := Found; // SearchFileB := Found;
✓
end;
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2019
✓
Question 6(b): Python
✓
def SearchFileNtoZ(SearchString):
✓
## FileData : String
✓
## Found : Boolean
✓
## MyFile : Text
✓
Found = False
✓
MyFile = open("UserListNtoZ.txt", 'r')
✓
FileData = MyFile.readline()
✓
while Filedata != "" and not Found :
✓
if SearchString + ' * ' == FileData[0: len(SearchString)+1]:
✓
Found = True
✓
FileData = MyFile.readline()
✓
MyFile.close
✓
return(Found)
✓
Question 6(d)(ii): Visual Basic
✓
Call ClearArray(Duplicates, 100, "Empty") 'Call optional
✓
Question 6(d)(ii): Pascal
✓
ClearArray(Duplicates, 100, 'Empty');
✓
Question 6(d)(ii): Python
✓
ClearArray(Duplicates, 100, "Empty")

Mark scheme 9608_w19_ms_21.pdf →

Show text version of question

Question 6

Part (d)

(ii)

Question 6

Account information for users of a library is held in one of two text files; UserListAtoM.txt and

UserListNtoZ.txt

The format of the data held in the two files is identical. Each line of the file is stored as a string that contains an account number, name and telephone number separated by the asterisk character ('*') as follows:

<Account Number>'*'<Name>'*'<Telephone Number>

An example of one line from the file is:

"GB1234*Kevin Mapunga*07789123456"

The account number string may be six or nine characters in length and is unique for each person. It is made up of alphabetic and numeric characters only.

An error has occurred and the same account number has been given to different users in the two files. There is no duplication of account numbers within each individual file.

A
program is to be written to search the two files and to identify duplicate entries. The account

number of any duplicate found is to be written to an array, Duplicates, which is a 1D array of 100 elements of data type STRING.

The program is to be implemented as several modules. The outline description of three of these is as follows:

Module Outline description

ClearArray()

  • Initialise the global array Duplicates. Set all elements to the
  • empty string.

  • Read each line from the file UserListAtoM.txt
  • Check whether the account number appears in file
  • UserListNtoZ.txt using SearchFileNtoZ() FindDuplicates() • If the account number does appear then add the account number to the array.

  • Output an error message and exit the module if there are more
  • duplicates than can be written to the array.

  • Search for a given account number in file UserListNtoZ.txt
  • SearchFileNtoZ()

  • If found, return TRUE, otherwise return FALSE

ClearArray() is to be modified to make it general purpose. It will be used to initialise any 1D array of data type STRING to any value.

It will now be called with three parameters as follows:

1. The array 2. The number of elements 3. The initialisation string

You should assume that the lower bound is 1.

(ii)

Write program code for a statement that calls the modified ClearArray() procedure

to clear the array Duplicates to "Empty".

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

Program code

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

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

[2]

Question 16

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

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of 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 "ABC"

RIGHT(ThisString: STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER returns the integer part of x

Example: INT(27.5415) returns 27

NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Note: This function will also work if x is of type INTEGER

Example: NUM_TO_STRING(87.5) returns "87.5"

STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string. Note: This function will also work if x is of type CHAR

Example: STRING_TO_NUM("23.45") returns 23.45

ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of ThisChar

Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR returns the character whose ASCII value is x

Example: CHR(87) returns 'W'

Question 17

UCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the upper case equivalent of ThisChar If ThisChar is not a lower case alphabetic character, it is returned unchanged.

Example: UCASE('a') returns 'A'

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 18

Question 19

Question 20

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 Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series.

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

Topic relevance

Why this question appears here

99% 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_w19_qp_21.pdf

Keep practising this topic