Question 6(c) 2021 · May-June · Paper 21 · 16 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (c)
Question 8
Show text version of question
Question 6
Part (c)
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 (c)
The module description of Unpack() is repeated here for reference.
Module Description
- called with two parameters:
- extracts the four data values from the string and assigns each
o an array index Unpack() o a string value read from one line of the backup file
to the appropriate array
Write program code for the module Unpack(). You may assume that the backup file contains only valid stock information.
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 21
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Question 22
Appendix Built‑in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns "BCD"
LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of ThisString
Example: LENGTH("Happy Days") returns 10
LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns "ABC"
RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns "FGH"
INT(x : REAL) RETURNS INTEGER returns the integer part of x
Example: INT(27.5415) returns 27
LCASE(ThisChar : CHAR) RETURNS CHAR returns the character value representing the lower case equivalent of ThisChar If ThisChar is not an upper case alphabetic character, it is returned unchanged.
Example: LCASE('W') returns 'w'
ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar
Example: ASC('A') returns 65
RAND(x : INTEGER) RETURNS REAL returns a real number in the range 0 to x (not inclusive of x).
Example: RAND(87) could return 35.43
NUM_TO_STRING(x : REAL) RETURNS STRING returns a string representation of a numeric value. Note: This function will also work if x is of type INTEGER
Example: NUM_TO_STRING(87.5) returns "87.5"
Question 23
Operators (pseudocode)
Operator Description Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE
Question 24
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.
Why this question appears here
99% 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
