Question 6(c) 2021 · May-June · Paper 22 · 14 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (c)
Question 8
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
Question 8
Show text version of question
Question 6
Part (c)
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 (c)
The module description of GetValidFilename() is as follows:
Module Description
- prompts and inputs a filename
- validates the filename by checking that it:
- is between 4 and 10 characters in length (inclusive)
- if the filename is invalid, outputs a warning message and
- otherwise returns the valid filename
GetValidFilename() • contains only alphanumeric characters
asks the user to try again
Write program code for the module GetValidFilename().
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 17
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................
Question 18
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
CHR(x : INTEGER) RETURNS CHAR returns the character whose ASCII value is x Example: CHR(87) returns 'W'
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 19
Question 20
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
91% 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_22.pdf
