Question 6(c) 2019 · May-June · Paper 23 · 3 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (c)
Question 3
Show text version of question
Question 6
Part (c)
Question 6
A text file, StudentContact.txt, contains a list of names and telephone numbers of students
in a school. Not all students in the school have provided a contact telephone number. In this case, their name will not be in the file.
Each line of the file is stored as a string that contains a name and telephone number, separated by the asterisk character ('*') as follows:
<Name>'*'<TelNumber>, for example:
"Bill Smith*081234567"
of 40 elements of string data type. You can assume that student names are unique. Unused elements contain the empty string "".
names and numbers for all students in a particular class.
For each name contained in the ClassList array, the program will:
- search the StudentContact.txt file
- copy the matching string into ClassContact.txt if the name is found
- write the name together with “*No number” into ClassContact.txt if the name is not found.
The program will be implemented as three modules. The description of these is as follows:
Module Description ProcessArray() • Check each element of the array: ○ Read the student name from the array ○ Ignore unused elements ○ Call SearchFile() with the student name ○ If the student name is found, call AddToFile() to write the student details to the class file ○ If the student name is not found, call AddToFile() to write a new string to the class file, formed as follows: <Name>“*No number”
- Return the number of students who have not provided a
telephone number SearchFile() • Search for a given student name at the start of each line in the file StudentContact.txt: ○ If the search string is found, return the text line from StudentContact.txt ○ If the search string is not found, return an empty string AddToFile() • Append the given string to a specified file, for example, AddToFile(StringName, FileName)
Question 15
Part (c)
ProcessArray() is modified to make it general purpose. It will now be called with two
parameters as follows:
- an array
- a string representing the name of a class contact file
It will still return the number of students who have not provided a contact telephone number.
Write program code for the header (declaration) of the modified ProcessArray().
Programming language ............................................................................................................
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Question 18
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.
Example: NUM_TO_STRING(x) returns "87.5" if x has the value 87.5 Note: This function will also work if x is of type INTEGER
STRING_TO_NUM(x : STRING) RETURNS REAL returns a numeric representation of a string.
Example: STRING_TO_NUM(x) returns 23.45 if x has the value "23.45" Note: This function will also work if x is of type CHAR
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 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_s19_qp_23.pdf
