Question 6(a) 2021 · May-June · Paper 21 · 12 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (a)
Question 4
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)
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]
- 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.
contains the ID for the product whose description is in Description[4].
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
- 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
- writes the string to the backup file
- calls Check() to validate the data values. If there is an error
- repeats for all stock items
- returns TRUE if nothing was written to "ERRORLOG.TXT",
- called with two parameters:
- extracts the four data values from the string and assigns each
index are valid
string. Inserts an asterisk character '*' as a separator between data values
Backup()
then also writes the string to the file "ERRORLOG.TXT"
otherwise returns FALSE
o an array index Unpack() o a string value read from one line of the backup file
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
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Question 18
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
