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

Question 6(a) 2019 · May-June · Paper 23 · 8 marks

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

Official answer for Question 6

Part (a)

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

Question 8

✓
scheme.
✓
Programming language example solutions appear in the Appendix.
✓
FUNCTION SearchFile (SearchString : STRING) RETURNS STRING
✓
DECLARE FileData : STRING
✓
DECLARE Found : BOOLEAN
✓
DECLARE SearchLength : INTEGER
✓
Found ← FALSE
✓
SearchLength ← LENGTH(SearchString)
✓
OPENFILE "StudentContact.txt" FOR READ
✓
WHILE NOT EOF("StudentContact.txt") AND NOT Found
✓
READFILE "StudentContact.txt", FileData
✓
IF SearchString = LEFT(FileData, SearchLength)
✓
THEN
✓
Found ← TRUE
✓
ENDIF
✓
ENDWHILE
✓
CLOSEFILE "StudentContact.txt"
✓
IF NOT FOUND
✓
THEN
✓
RETURN ""
✓
ELSE
✓
RETURN FileData
✓
ENDIF
✓
ENDFUNCTION
✓
One mark for each of the following:
✓
1.
✓
Function header and end (where appropriate). Parameter optional but if
✓
present must be of type STRING
✓
2.
✓
Calculate length of string from parameter // extract substring from file line
✓
3.
✓
File OPEN() in READ mode and subsequent CLOSE()
✓
4.
✓
WHILE loop repeating until EOF()
✓
5.
✓
read a line from the file in a loop
✓
6.
✓
compare name from file with SearchString in a loop
✓
7.
✓
exit loop if SearchString found
✓
8.
✓
Return the line from the file if SearchString found or an empty string if not
✓
found
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s19_ms_23.pdf →

Show text version of question

Question 6

Part (a)

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 (a)

Write program code for the module SearchFile().

Visual Basic and Pascal: You should include the declaration statements for variables. Python: You should show a comment statement for each variable used with its data type.

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[8]

Question 16

Topic relevance

Why this question appears here

82% assigned-topic match · Programming › Constructs

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