Past-paper question · 2021 May-June · Paper 21 · Q6(b)

Question 6(b) 2021 · May-June · Paper 21 · 16 marks

Original past-paper question for 6(B)
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)

Question 8

✓
FUNCTION Backup() RETURNS BOOLEAN
✓
DECLARE Index : INTEGER
✓
DECLARE FileName, FileLine : STRING
✓
DECLARE AllOK : BOOLEAN
✓
CONSTANT ASTERISK = '*'
✓
AllOK ← TRUE
✓
FileName ← GetValidFileName()
✓
OPENFILE Filename FOR WRITE
✓
OPENFILE "ERRORLOG.TXT" FOR WRITE
✓
FOR Index ← 1 TO 10000
✓
IF StockID[Index]<> “”
✓
THEN
✓
FileLine ← StockID[Index] & ASTERISK
✓
FileLine ← FileLine & Description[Index] & ASTERISK
✓
FileLine ← FileLine & NUM_TO_STRING(Quantity[Index]) &
✓
ASTERISK
✓
FileLine ← FileLine & NUM_TO_STRING(Cost[Index])
✓
WRITEFILE FileName, FileLine
✓
//now check for sensible data
✓
IF Check(Index) <> TRUE
✓
THEN
✓
WRITEFILE, "ERRORLOG.TXT", FileLine
✓
AllOK ← FALSE
✓
ENDIF
✓
ENDIF
✓
ENDFOR
✓
CLOSEFILE FileName
✓
CLOSEFILE "ERRORLOG.TXT"
✓
RETURN AllOK
✓
ENDFUNCTION

Mark scheme 9608_s21_ms_21.pdf →

Show text version of question

Question 6

Part (b)

Question 6

A program stores stock data in four global arrays as follows:

Example Initial data Array Data type Description data value value The stock item ID StockID STRING "HWDM0001" "" (Eight alpha-numeric characters)

A
description of the item

Description STRING "Candle" "" (Alphabetic characters only) Quantity INTEGER The number in stock 4 0 Cost REAL The cost of the item 2.75 0

  • Each array contains 10 000 elements.
  • Elements with the same index relate to the same stock item. For example, StockID[4]
  • contains the ID for the product whose description is in Description[4].

  • The StockID array is not sorted and unused elements may occur at any index position.
  • Unused elements are assigned the initial data value shown in the table above.

The program is to be modified so that the data from the arrays can be stored in a text file for backup.

The programmer has started to define program modules as follows:

Module Description GetValidFilename() • prompts, inputs and returns a valid filename

  • called with an array index as a parameter

Check()

  • checks that the data values for the stock item with the given
  • index are valid

  • returns TRUE if the values are valid, otherwise returns FALSE
  • calls GetValidFilename() to get the name of the backup file
  • combines the data values for each stock item to form a single
  • string. Inserts an asterisk character '*' as a separator between data values

  • writes the string to the backup file
  • Backup()

  • calls Check() to validate the data values. If there is an error
  • then also writes the string to the file "ERRORLOG.TXT"

  • repeats for all stock items
  • returns TRUE if nothing was written to "ERRORLOG.TXT",
  • otherwise returns FALSE

  • called with two parameters:
  • o an array index Unpack() o a string value read from one line of the backup file

  • extracts the four data values from the string and assigns each

to the appropriate array

Question 17

Part (b)

Write pseudocode for the module Backup().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Question 19

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

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

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

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

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

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

[8]

Question 20

Topic relevance

Why this question appears here

83% assigned-topic match · Data types and structures › Data types and records

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

Keep practising this topic