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

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

Question 8

✓
FUNCTION Restore(Filename : STRING) RETURNS BOOLEAN
✓
DECLARE Index : INTEGER
✓
DECLARE FileLine : STRING
✓
DECLARE Success : BOOLEAN
✓
Success ← TRUE
✓
OPENFILE Filename FOR READ
✓
READFILE Filename, FileLine
✓
IF FileLine = "" THEN
✓
//alt: IF EOF(filename)
✓
CLOSEFILE Filename
✓
RETURN FALSE
✓
//file is empty
✓
ENDIF
✓
FOR Index ← 1 TO 10000
✓
//first initialise arrays
✓
StockID[Index] ← ""
✓
Description[Index] ← ""
✓
Quantity[Index] ← 0
✓
Cost[Index] ← 0.0 // 0
✓
ENDFOR
✓
Index ← 1
✓
//starts loop with first FileLine
✓
WHILE NOT EOF(Filename) AND Index <= 10000
✓
CALL Unpack(Index, FileLine)
✓
Index ← Index + 1
✓
READFILE Filename, FileLine
✓
ENDWHILE
✓
IF Index = 10001 AND NOT EOF(Filename) THEN
✓
Success ← FALSE
✓
ENDIF
✓
CLOSEFILE Filename
✓
RETURN Success
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Function heading including input parameter and function End

Question 2

✓
Declare local variable for line read from file

Question 3

✓
OPEN file in READ mode and CLOSE

Question 4

✓
Check whether file is empty and return FALSE if it is (no restore

Question 5

✓
Loop through all 10 000 elements initialising arrays

Question 6

✓
Loop until EOF(Filename) OR Index > 10000

Question 7

✓
Call Unpack() correctly for each line from the file in a loop

Question 8

✓
Return FALSE if more than 10000 lines in file, otherwise returns TRUE
✓
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 (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 "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 (b)

Write pseudocode for the module Restore().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Question 15

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

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

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

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

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

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

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

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

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

[8]

Question 16

Topic relevance

Why this question appears here

83% 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

Keep practising this topic