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

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

Question 8

✓
FUNCTION CheckBackupFile() RETURNS STRING
✓
DECLARE Filename, FileLine, Response : STRING
✓
Filename ← ""
✓
WHILE Filename = ""
✓
Filename ← GetValidFilename()
✓
OPENFILE Filename FOR READ
✓
READFILE Filename, FileLine
✓
CLOSEFILE Filename
✓
IF FileLine <> "" //check if data in file
✓
THEN
✓
OUTPUT "File already exists – do you want to
✓
overwrite? "
✓
INPUT Response
✓
IF Response <> "Yes"
✓
THEN
✓
Filename ← ""
✓
OUTPUT "Please input a different
✓
filename "
✓
ENDIF
✓
ENDIF
✓
ENDWHILE
✓
RETURN Filename
✓
ENDFUNCTION
✓
One mark for each of the following:

Question 1

✓
Conditional loop

Question 2

✓
Use of GetValidFilename()in a loop

Question 3

✓
OPEN file in READ mode and CLOSE in a loop

Question 4

✓
Test if file not empty (using EOF() or READ empty string)

Question 5

✓
If not empty, prompt and input (in case of a non-empty file) in a loop

Question 6

✓
…. and process response

Question 7

✓
Set loop termination condition by checking for new file or overwrite
✓
confirmed
✓
in a loop

Question 8

✓
Return Filename
✓
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 (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 (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 (a)

Write pseudocode for the module CheckBackupFile().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[8]

Question 18

Topic relevance

Why this question appears here

83% assigned-topic match · Programming › Constructs

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