Past-paper question · 2021 May-June · Paper 23 · Q6(b)

Question 6(b) 2021 · May-June · Paper 23 · 16 marks

Original past-paper question for 6(B)
Original past-paper question for 6(B)
Original past-paper question for 6(B)
Original past-paper question for 6(B)
Reveal official mark-scheme answer Official mark-scheme answer for 6(B)

Official answer for Question 6

Part (b)

✓
‘Pseudocode’ solution included here for development and clarification of

Question 6

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix
✓
PROCEDURE GroupReport(Group : STRING)
✓
DECLARE Total : REAL
✓
DECLARE Count, Index : INTEGER
✓
Total ← 0
✓
Count ← 0
✓
FOR Index ← 1 TO 10000
✓
IF LEFT(StockID[Index], 4) = Group
✓
THEN
✓
Count ← Count + 1
✓
Total ← Total + (Quantity[Index] *
✓
Cost[Index])
✓
ENDIF
✓
ENDFOR
✓
IF Count = 0
✓
THEN
✓
OUTPUT
✓
"There are no items in Group: ", Group
✓
ELSE
✓
OUTPUT
✓
"Group: ", Group
✓
OUTPUT
✓
"Number of items in Group: ", Count
✓
OUTPUT
✓
"Total value of items in Group: ", Total
✓
ENDIF
✓
ENDPROCEDURE
✓
1 mark for each of the following:

Question 1

✓
Procedure heading and ending including input parameter

Question 2

✓
Declare and initialise local variables for Total and Count

Question 3

✓
Loop through all 10 000 elements (allow LEN(StockID)

Question 4

✓
Check for required group using substring function in a loop

Question 5

✓
...Increment Count and sum Total using correct array notation

Question 6

✓
Generate both sets of output as appropriate after loop
✓
9608/23
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_23.pdf →

Show text version of question

Question 6

Part (b)

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 (eight alpha-numeric "ABLK0001" "" characters) a description of the item Description STRING "torch" "" (alphabetic characters only) Quantity INTEGER the number in stock 6 0

Cost REAL the cost of the item 4.80 0.0

  • Each array contains 10 000 elements.
  • Elements with the same index relate to the same stock item. For example, StockID[5]

contains the ID for the product whose description is in Description[5].

  • 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.
  • The first four characters of the StockID represent a product group. The last four characters

represent the item within the group.

The program is to be modified so that:

  • data from the arrays are stored in a text file for backup purposes. Data from unused elements

are not stored in the file.

  • a Summary array is added. This will be a global 1D array of 500 elements of type STRING.

Each product group will occur once in the array, for example "ABLK" for the item in the table above.

The programmer has started to define program modules as follows:

Module Description

  • prompts and inputs a filename
  • GetValidFilename()

  • returns a valid filename as a STRING
  • calls GetValidFilename() for a filename
  • checks if the file is empty
  • CheckBackupFile() • If the file is not empty ask the user to confirm that overwrite is intended. If not intended allow the user to re-input a different filename.

  • returns the filename.

Question 17

Part (b)

Write program code for a module GroupReport(), which will summarise the stock data for

a given product group.

The product group will be passed to the module as a string. The total value of items is calculated by multiplying the cost by the quantity.

An example of the output for group ABLK is as follows:

Group: ABLK Number of items in Group: 11 Total value of items in Group: 387.89

If no items are found for group ABLK, the output is as follows:

There are no items in Group: ABLK

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 19

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

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

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

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

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

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

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

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

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

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

[6]

Question 20

Topic relevance

Why this question appears here

83% assigned-topic match · Programming › Structured programming

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_23.pdf

Keep practising this topic