Past-paper question · 2019 May-June · Paper 23 · Q6(c)

Question 6(c) 2019 · May-June · Paper 23 · 3 marks

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

Official answer for Question 6

Part (c)

✓
‘Pseudocode’ solution included here for development and clarification of mark

Question 3

✓
scheme.
✓
Programming language example solutions appear in the Appendix.
✓
FUNCTION ProcessArray (ClassList : ARRAY, ClassContact :
✓
STRING)
✓
RETURNS : INTEGER
✓
One mark per underlined section.
✓
*** End of Mark Scheme – example program code solutions follow ***
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Program Code Example Solutions
✓
Q6 (a): Visual Basic
✓
Function SearchFile(SearchString As String) As String
✓
Dim FileData As String
✓
Dim Found As Boolean
✓
Dim SearchLength As Integer
✓
Dim FileName As String
✓
Found = False
✓
SearchLength = Len(SearchString)
✓
FileName = "StudentContact.txt"
✓
FileOpen(1, FileName, OpenMode.Input)
✓
While Not EOF(1) And NOT Found
✓
FileData = LineInput(1)
✓
If SearchString = Left(FileData, SearchLength) Then
✓
Found = True
✓
End If
✓
End While
✓
FileClose(1)
✓
If Not Found Then
✓
Return ""
✓
Else
✓
Return FileData
✓
End If
✓
End Function
✓
Alternative:
✓
Function SearchFile (SearchString As String) As String
✓
Dim FileData As String
✓
Dim Found As Boolean
✓
Dim SearchLength As Integer
✓
Dim MyFile As System.IO.StreamReader
✓
MyFile = My.Computer.FileSystem.OpenTextFileReader("StudentContact.txt")
✓
Found = False
✓
SearchLength = Len(SearchString)
✓
Do While MyFile.Peek <> -1
✓
FileData = MyFile.Readline()
✓
If SearchString = LEFT(FileData, SearchLength) Then
✓
Found = True
✓
return(FileData)
✓
End If
✓
Loop
✓
MyFile.Close
✓
If NOT Found then
✓
return ("")
✓
End If
✓
End Function
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Q6 (a): Pascal
✓
function SearchFile(var SearchString: string):string;
✓
var Found : Boolean;
✓
SearchLength : integer;
✓
FileData : string;
✓
MyFile : text;
✓
begin
✓
Found := False;
✓
SearchLength := Length(SearchString);
✓
Assign(MyFile, 'StudentContact.txt');
✓
Reset(MyFile);
✓
While NOT EOF(MyFile) AND Found = False do
✓
Begin
✓
Readln(MyFile, FileData);
✓
If SearchString = LeftStr(FileData,SearchLength) then
✓
Found := True;
✓
End;
✓
Close(MyFile);
✓
If NOT Found then
✓
SearchFile := ''
✓
else
✓
SearchFile := FileData;
✓
End;
✓
Q6 (a): Python
✓
def searchFile(searchString):
✓
##Declare filedata : string, found : boolean, searchLength : integer
✓
##returns a string value
✓
found = False
✓
searchLength = len(searchString)
✓
myFile = open("StudentContact.txt", 'r')
✓
fileData = myFile.readline()
✓
while found == False:
✓
fileData = myFile.readline()
✓
if not fileData.strip(): #check if no data/end of file
✓
break
✓
else:
✓
if searchString == fileData[0:searchLength]:
✓
found = True
✓
print(searchString)
✓
myFile.close
✓
if found == False:
✓
return("")
✓
else:
✓
return(fileData)
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Q6 (c): Visual Basic
✓
Function ProcessArray (ClassList() As String, ClassContact As String) As
✓
Integer
✓
OR
✓
Function ProcessArray (ClassList As String(), ClassContact As String) As
✓
Integer
✓
Q6 (c): Pascal
✓
function ProcessArray (var ClassList:CList; ClassContact:string) :integer;
✓
CList is user-defined type – could be any name that’s not a keyword
✓
Q6 (c): Python
✓
def ProcessArray (ClassList, ClassContact) :

Mark scheme 9608_s19_ms_23.pdf →

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"

A
1D array, ClassList, contains the names of students in a particular class. The array consists

of 40 elements of string data type. You can assume that student names are unique. Unused elements contain the empty string "".

A
program is to be written to produce a new text file, ClassContact.txt, containing student

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

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

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

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

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

[3]

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.

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_s19_qp_23.pdf

Keep practising this topic