2.3.1 Algorithms - Design of algorithms
2.3.1 Algorithms - Design of algorithms
An online supermarket keeps a record of a customer's favourite items based on what they have ordered in the
past. The list (barcodes) of favourite items is kept in a serial file called Favourites.dat. When an item is added to
the online shopping basket, its barcode is passed to procedure UpdateFavourites, which checks to see if it is
already in the favourite items file. If it is not, the procedure appends the item to the end of the favourite items file.
Assume the Favourites.dat file exists. Write an algorithm for the procedure UpdateFavourites.
[8]
Explain how you would search the sequential file to find the target record.
[5]
PROCEDURE ChangeInteger(Value:INTEGER)
INTEGER P, X, M
REPEAT
P = Value DIV 10
X = P * 10
M = Value − X
OUTPUT M
Value = P
OUTPUT ‘+’
END PROCEDURE
(i) Complete the trace table for the following procedure call ChangeInteger(4082).
Value P X M OUTPUT
[3]
(ii) Complete the trace table for the following procedure call ChangeInteger(-243).
Value P X M OUTPUT
[4]
© OCR 2019. 5 of 9
Question Answer/Indicative content Marks Guidance
1 a Open Favourites.dat 8 Ignore for this question file open mode (i.e.
Set FOUND flag to FALSE WRITE,READ & APPEND)
Loop { includes correct end condition }
Read record from Favourites file Allow the use of flags to indicate EOF of
If record from Favourites file = barcode files
passed …
… FOUND flag set to TRUE Until EOF Accept flow chart solutions – if the flow is
Favourites.dat OR FOUND=TRUE right for item fond and not found also
Close Favourites file award bullet points 2, 5 & 6 ( Found flag)
IF FOUND = FALSE Open Favourites
file A fully working solution should be given full
Write barcode to Favourites file marks regardless of efficiency.
Close Favourites file
Examiner's Comments
Total 13
b Example answer: 4
PROCEDURE
ChangeInteger(Value:INTEGER)
INTEGER P, X, M
BOOLEAN NegativeFlag = FALSE
REPEAT
P = Value DIV 10
X = P* 10
M = Value –X
OUTPUT M
Value = P
END PROCEDURE
Total 9