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

Question 6(a) 2021 · May-June · Paper 22 · 11 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

Question 5

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix.
✓
PROCEDURE StockSummary()
✓
DECLARE Index, Count : INTEGER
✓
DECLARE Total : REAL
✓
Count ← 0
✓
Total ← 0.0
✓
FOR Index ← 1 TO 10000
✓
IF StockID[Index]) <> "" THEN
✓
Count ← Count + 1
✓
Total ← Total + (Quantity[Index] * Cost[Index])
✓
ENDIF
✓
ENDFOR
✓
OUTPUT "Total Value is ", Total
✓
OUTPUT "Number of Stock Entries is ", Count
✓
ENDPROCEDURE
✓
One mark for each of the following:

Question 1

✓
Declaration and initialisation of Count and Total (by comment in
✓
Python)

Question 2

✓
Loop for 10000 elements

Question 3

✓
Skip row when StockID element = "" in a loop

Question 4

✓
Increment Count and sum Total in a loop

Question 5

✓
OUTPUT the total and the count after the loop (following a reasonable
✓
attempt at MP4)
✓
9608/22
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_22.pdf →

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]
  • contains the ID for the product whose description is in Description[3].

  • The StockID array is not sorted.

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
  • Unpack()

  • 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

  • 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
  • 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

  • returns FALSE if the arrays are full but there are still lines in the
  • file, otherwise returns TRUE For all items where StockID does not contain the initial value:

  • counts the number of stock entries in the StockID array
  • StockSummary() • outputs the overall value of all items in stock (cost multiplied by the quantity)

  • outputs the number of stock entries

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[5]

Question 14

Topic relevance

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

Keep practising this topic