Question 6(d)(ii) 2019 · October-November · Paper 21 · 2 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (d)
(ii)
Question 2
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.
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
- Read each line from the file UserListAtoM.txt
- Check whether the account number appears in file
- Output an error message and exit the module if there are more
- Search for a given account number in file UserListNtoZ.txt
- If found, return TRUE, otherwise return FALSE
empty string.
UserListNtoZ.txt using SearchFileNtoZ() FindDuplicates() • If the account number does appear then add the account number to the array.
duplicates than can be written to the array.
SearchFileNtoZ()
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
...........................................................................................................................................
...........................................................................................................................................
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.
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
