Past-paper question · 2023 May-June · Paper 21 · Q8(b)

Question 8(b) 2023 · May-June · Paper 21 · 7 marks

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

Official answer for Question 8

Part (b)

✓
FUNCTION CheckNewItem(NewLine : STRING) RETURNS BOOLEAN

Question 7

✓
DECLARE NotFound : BOOLEAN
✓
DECLARE NewItemNum, ThisItemNum, ThisLine : STRING
✓
NotFound TRUE
✓
OPENFILE "Stock.txt" FOR READ
✓
NewItemNum LEFT(NewLine, 4)
✓
ThisItemNum "0000" //rogue initial value
✓
WHILE NOT EOF("Stock.txt") AND NotFound = TRUE AND__
✓
ThisItemNum < NewItemNum
✓
READFILE("Stock.txt", ThisLine) //brackets optional
✓
ThisItemNum LEFT(ThisLine, 4)
✓
IF ThisItemNum = NewItemNum THEN
✓
NotFound FALSE
✓
ENDIF
✓
ENDWHILE
✓
CLOSEFILE "Stock.txt"
✓
RETURN NotFound
✓
ENDFUNCTION
✓
Mark as follows:

Question 1

✓
Open Stock.txt in READ mode and subsequently close

Question 2

✓
Extract NewItemNum from parameter

Question 3

✓
Conditional loop until EOF("Stock.txt")

Question 4

✓
... OR NewItemNum found

Question 5

✓
... OR when ThisItemNum < NewItemNum

Question 6

✓
Read a line from Stock.txt AND extract ThisItemNum in a
✓
loop

Question 7

✓
If ThisItemNum = NewItemNum then terminate loop / set flag in
✓
a loop

Question 8

✓
Return Boolean after reasonable attempt

Mark scheme 9618_s23_ms_21.pdf →

Show text version of question

Question 8

Part (b)

Question 8

A computer shop assembles 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 for each item in the range ItemNum 4 numeric characters "0001" to "5999" inclusive

SupplierCode 5 alphabetic characters 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.

A
programmer has started to define program modules as follows:

Module Description SuppExists() • called with a parameter of type string representing a supplier code (already written)

  • returns TRUE if the supplier code is already in use, otherwise returns
  • FALSE IsNewSupp() • called with a parameter of type string representing a new supplier code

  • returns TRUE if the string only contains alphabetic characters (either

upper or lower case) and the supplier code is not already in use, otherwise returns FALSE

Question 15

Part (b)

A new module has been defined:

Module Description CheckNewItem() • called with a parameter of type string representing a line of item information

  • checks to see whether an item with the same ItemNum already
  • exists in the file

  • returns TRUE if the ItemNum is not already in the file, otherwise

returns FALSE

Write efficient pseudocode for module CheckNewItem().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Question 17

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

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

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

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

[7]
Topic relevance

Why this question appears here

71% 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_21.pdf

Keep practising this topic