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

Question 6(a) 2021 · May-June · Paper 21 · 12 marks

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

Official answer for Question 6

Part (a)

✓
'Pseudocode' solution included here for development and clarification of the mark

Question 4

✓
scheme.
✓
Programming language example solutions appear in the Appendix.
✓
FUNCTION Check(Index : INTEGER) RETURNS BOOLEAN
✓
IF LENGTH(StockID[Index]) <> 8 OR __
✓
Description[Index]) = "" OR __
✓
Quantity[Index] < 0
✓
THEN
✓
RETURN FALSE
✓
ELSE
✓
RETURN TRUE
✓
ENDIF
✓
ENDFUNCTION
✓
One mark for each of the following:

Mark scheme 9608_s21_ms_21.pdf →

Show text version of question

Question 6

Part (a)

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

Write program code for the module Check().

Data values relating to an individual stock item are valid if:

  • the StockID element is of length 8
  • the Description is not an empty string
  • the Quantity is zero or above.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[4]

Question 18

Topic relevance

Why this question appears here

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

Keep practising this topic