Question 6(a) 2021 · May-June · Paper 22 · 11 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (a)
Question 5
Question 1
Question 2
Question 3
Question 4
Question 5
Show text version of question
Question 6
Part (a)
Question 6
A program stores data about stock items in four global 1D arrays as follows:
Example Initial data Array Data type Description data value value the stock item ID StockID STRING "JBCD0002" "" (eight alpha-numeric characters) a description of the item Description STRING "soap" "" (alphabetic characters only) Quantity INTEGER the number in stock 9 0 Cost REAL the cost of the item 1.45 0.0
- Each array contains 10 000 elements.
- Elements with the same index relate to the same stock item. For example, StockID[3]
- The StockID array is not sorted.
contains the ID for the product whose description is in Description[3].
The program will be modified so that the data from the arrays can be stored in a text file for backup. You may assume that a backup file contains only valid stock data.
The programmer has started to define program modules as follows:
Module Description
- called with two parameters:
- an array index
- a string value read from one line of the backup file
- extracts the four data values from the string and assigns each
- called with a string representing the name of a backup file
- returns FALSE if the file is empty
- sets all elements of each array to the initial data value as given
- returns FALSE if the arrays are full but there are still lines in the
- counts the number of stock entries in the StockID array
- outputs the number of stock entries
Unpack()
to the appropriate array
in the table Restore() • reads the backup file line by line calls Unpack() to extract data from each line and assign values to the corresponding arrays
file, otherwise returns TRUE For all items where StockID does not contain the initial value:
StockSummary() • outputs the overall value of all items in stock (cost multiplied by the quantity)
Question 13
Part (a)
Write program code for the module StockSummary().
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 14
Why this question appears here
87% assigned-topic match · Data types and structures › Arrays
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_22.pdf
