Past-paper question · 2018 October-November · Paper 22 · Q4(b)

Question 4(b) 2018 · October-November · Paper 22 · 8 marks

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

Official answer for Question 4

Part (b)

✓
Pseudocode solution included here for development and clarification of

Question 8

✓
mark scheme.
✓
Programming language solutions appear at the end of this mark scheme.
✓
FUNCTION ScanFile(SearchString STRING) RETURNS INTEGER
✓
DECLARE
✓
FileData : STRING
✓
DECLARE
✓
FileLine : INTEGER
✓
DECLARE
✓
NewData : STRING
✓
DECLARE
✓
Size : INTEGER
✓
NextArrayElement ← 1
✓
FileLine ← 1
✓
FileData ← ReadFileLine("DataFile.txt", FileLine)
✓
WHILE FileData <> ""
✓
IF LEFT(FileData, 7) = SearchString
✓
THEN
✓
Size ← LENGTH(FileData)
✓
NewData ← RIGHT(FileData,Size-7)
✓
ResultArray[NextArrayElement] ← NewData
✓
NextArrayElement ← NextArrayElement + 1
✓
ENDIF
✓
FileLine ← FileLine + 1
✓
FileData ← ReadFileLine("DataFile.txt", FileLine)
✓
ENDWHILE
✓
CALL ScanCompleted()
✓
RETURN FileLine
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Function heading and ending including parameters and return
✓
statement

Question 2

✓
Local variable declarations for FileData and FileLine but NOT
✓
declaration of NextArrayElement

Question 3

✓
initialisation of FileLine and NextArrayElement (allow 0 or 1)

Question 4

✓
WHILE ... ENDWHILE loop

Question 5

✓
Comparing SearchString with first seven characters of FileData

Question 6

✓
Use of substring function and subtraction of 7 from length

Question 7

✓
Assign NewData to array ResultArray following attempt at MP6

Question 8

✓
Increment NextArrayElement and FileLine (as above)

Mark scheme 9608_w18_ms_22.pdf →

Show text version of question

Question 4

Part (b)

Question 4

Part of a program written in pseudocode is shown.

010 DECLARE NextArrayElement : INTEGER

…

100 FUNCTION ScanFile(SearchString: STRING) RETURNS INTEGER 101 102 DECLARE FileData : STRING 103 DECLARE FileLine : INTEGER 104 105 NextArrayElement 1 106 FileLine 1 107 FileData ReadFileLine("DataFile.txt", FileLine) 108 109 WHILE FileData <> "" 110 IF LEFT(FileData, 7) = SearchString 111 THEN 112 ResultArray[NextArrayElement] FileData 113 NextArrayElement NextArrayElement + 1 114 ENDIF 115 FileLine FileLine + 1 116 FileData ReadFileLine("DataFile.txt", FileLine) 117 ENDWHILE 118 119 CALL ScanCompleted() 120 RETURN FileLine 121 122 ENDFUNCTION

Part (b)

The function ScanFile() is to be amended so that the first 7 characters of FileData are

not written to the array.

Write program code to implement this amended ScanFile() function.

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 12

Topic relevance

Why this question appears here

72% assigned-topic match · Hardware › Logic gates and logic circuits

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

Keep practising this topic