Past-paper question · 2023 May-June · Paper 23 · Q8(a)

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

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

Official answer for Question 8

Part (a)

✓
FUNCTION ChangeSupp(Code1, Code2 : STRING) RETURNS

Question 8

✓
INTEGER
✓
DECLARE Count : INTEGER
✓
DECLARE ThisLine, ThisCode : STRING
✓
OPENFILE "Stock.txt" FOR READ
✓
OPENFILE "NewStock.txt" FOR WRITE
✓
Count 0
✓
WHILE NOT EOF("Stock.txt")
✓
READFILE("Stock.txt ", ThisLine) // brackets
✓
optional
✓
ThisCode MID(ThisLine, 5, 3)
✓
IF ThisCode = Code1 THEN
✓
ThisLine LEFT(ThisLine, 4) & Code2
✓
& RIGHT(ThisLine,
✓
LENGTH(ThisLine) - 7)
✓
Count Count + 1
✓
ENDIF
✓
WRITEFILE("NewStock.txt", ThisLine) // brackets
✓
optional
✓
ENDWHILE
✓
CLOSEFILE "NewStock.txt"
✓
CLOSEFILE "Stock.txt"
✓
RETURN Count
✓
ENDFUNCTION
✓
MP1
✓
Open both files, in correct modes, and subsequently close
✓
MP2
✓
Conditional loop until EOF(“Stock.txt”)
✓
MP3
✓
Read a line from Stock.txt AND extract ThisCode in a loop
✓
MP4
✓
Test ThisCode = Code1 AND if true, increment Count (must
✓
have been Initialised)in a loop
✓
MP5
✓
Update ThisLine using substring functions and '&' in a loop
✓
MP6
✓
completely correct update of ThisLine in a loop
✓
MP7
✓
Write ThisLine to NewStock.txt in a loop
✓
MP8
✓
Return count after loop
✓
9618/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2023
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s23_ms_23.pdf →

Show text version of question

Question 8

Part (a)

Question 8

A computer shop assembles desktop computers, using items bought from several suppliers. A text

file Stock.txt contains information about each item.

Information for each item is stored as a single line in the Stock.txt file in the format:

<ItemNum><SupplierCode><Description>

Item information is as follows:

Format Comment unique number for each item in the range “0001” ItemNum 4 numeric characters to “5999” inclusive SupplierCode 3 alphabetic characters code to identify the supplier of the item

Description a string a minimum of 12 characters

The file is organised in ascending order of ItemNum and does not contain all possible values in the range.

The programmer has defined the first program module as follows:

Module Description ChangeSupp() • called with two parameters Code1 and Code2 of type string that represent valid supplier codes

  • creates a new file NewStock.txt from the contents of the
  • file Stock.txt where any reference to Code1 is replaced by Code2

  • returns a count of the number of items that have had their supplier code

changed

Question 15

Part (a)

Write pseudocode for module ChangeSupp().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[8]

Question 16

Topic relevance

Why this question appears here

75% 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 9618_s23_qp_23.pdf

Keep practising this topic