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

Question 6(b) 2019 · May-June · Paper 23 · 9 marks

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

Official answer for Question 6

Part (b)

✓
FUNCTION ProcessArray() RETURNS INTEGER

Question 9

✓
DECLARE
✓
NoTelNumber : INTEGER
✓
DECLARE
✓
Index : INTEGER
✓
DECLARE
✓
ThisName : STRING
✓
DECLARE
✓
StudentData : STRING
✓
NoTelNumber ← 0
✓
FOR Index ← 1 to 40
✓
ThisName ← ClassList[Index]
✓
IF ThisName <> "" //Skip blanks
✓
THEN
✓
StudentData ← SearchFile(ThisName)
✓
IF StudentData = "" //Student not found
✓
THEN
✓
StudentData ← ThisName & "*No number"
✓
NoTelNumber ← NoTelNumber + 1
✓
ENDIF
✓
CALL AddToFile(StudentData, "ClassContact.txt")
✓
ENDIF
✓
ENDFOR
✓
RETURN NoTelNumber
✓
ENDFUNCTION
✓
One mark for each of the following:
✓
1.
✓
Function header and end, including return parameter
✓
2.
✓
Declaration and initialisation of local count variable (NoTelNumber)
✓
3.
✓
FOR loop for 40 array elements «
✓
4.
✓
skip empty elements in a loop
✓
5.
✓
use SearchFile(ThisName) and save return value in a loop
✓
6.
✓
if Searchfile() returns an empty string, add "*No number" to
✓
SearchString …
✓
7.
✓
... and increment count
✓
8.
✓
call AddToFile with both parameters as above in a loop
✓
9.
✓
Return count outside the loop

Mark scheme 9608_s19_ms_23.pdf →

Show text version of question

Question 6

Part (b)

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

Write pseudocode for the module ProcessArray().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[9]

Question 17

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