1(a).
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]
© OCR 2019. 1 of 9 PhysicsAndMathsTutor.com
(b). The supermarket has decided to change the favourite items file from serial to a sequential file.
Explain how you would search the sequential file to find the target record.
[5]
© OCR 2019. 2 of 9 PhysicsAndMathsTutor.com
2(a). The procedure below manipulates a passed integer value and gives a single or multiple outputs.
PROCEDURE ChangeInteger(Value:INTEGER)
INTEGER P, X, M
REPEAT
P = Value DIV 10
X = P * 10
M = Value − X
OUTPUT M
Value = P
UNTIL Value <= 0
OUTPUT ‘+’
END PROCEDURE
For example, ChangeInteger(1234) would output 4 3 2 1 +
(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
© OCR 2019. 3 of 9 PhysicsAndMathsTutor.com
[2]
© OCR 2019. 4 of 9 PhysicsAndMathsTutor.com
(b). The output produced for a negative value is not in the correct format of digit(s) and a single sign. Modify the
procedure ChangeInteger to give the correct format output for both positive and negative values.
[4]
END OF QUESTION PAPER
© 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
As with all algorithm questions this was
poorly answered, with most candidates
only achieving the open and close file
marks. Most of the candidates did not
know how to process a file and read
records from the file. A typical answer was
to treat the file as an array, for example to
access a record they used “Favourites.dat[
i ]” or to iterate through the file “for i to
Favourites.dat.length”, so achieving no
marks. The lack of detail in the algorithm
was also a problem with statements such
as “if Barcode not in file add to file”.
© OCR 2019. 6 of 9 PhysicsAndMathsTutor.com
Question Answer/Indicative content Marks Guidance
b Basic structure to be described: 5 Accept a binary search
Open file Find centre point
Is target equal to value? If yes return
found
Loop {includes correct end condition} If left pointer = right pointer then return
Read record not found
If target = record read Else take correct subset
Return found Repeat bullets 1, 2, 3 & 4
End if
If target > record read Examiner's Comments
Return not found
End if The main problem the candidates had with
Until EOF this question is that they described how to
Close file find the record in an index sequential file
Return not found and not a sequential file. It is extremely
difficult to describe the required search
using prose but this is what nearly all
responses tried to do. Many candidates
referred to “check if it's the right record and
if not repeat” without saying exactly what to
repeat and without reading a record
anyway. They may have found a numbered
bullet point response easier.
Total 13
© OCR 2019. 7 of 9 PhysicsAndMathsTutor.com
Question Answer/Indicative content Marks Guidance
2 a i Value P X M OUTP 3 If zero marks then mark the first row.
UT Ignore duplicate zeros at the end of the
first 4 columns.
4082 408 4080 2 2
408 40 400 8 8 Examiner's Comments
40 4 40 0 0
Candidates have in the past found trace
4 0 0 4 4
table difficult to complete. However many
(0) + candidates achieved full marks on this
question, with most gaining at least one
mark.
Columns Value & P correct
Columns X & M
Column OUTPUT correct
ii Value P X M OUTP 2 Examiner's Comments
UT
Those that did poorly on the previous
–243 –24 –240 –3 –3
question rarely got a mark here.
(–24) +
Columns Value, P and X correct
Columns M & OUTPUT correct
© OCR 2019. 8 of 9 PhysicsAndMathsTutor.com
Question Answer/Indicative content Marks Guidance
b Example answer: 4
PROCEDURE
ChangeInteger(Value:INTEGER)
INTEGER P, X, M
BOOLEAN NegativeFlag = FALSE
IF Value < 0 THEN
Value = Value*–1
NegativeFlag = TRUE
END IF
REPEAT
P = Value DIV 10
X = P* 10
M = Value –X
OUTPUT M
Value = P
UNTIL Value <= 0
IF NegativeFlag = TRUE THEN
OUTPUT ‘–‘
ELSE
OUTPUT ‘+’
END IF
END PROCEDURE
Checking to see if Value is less than Alternative possible solution is to use
zero ABS(M).
Correct output of negative value digits
… Examiner's Comments
… and still correctly outputting positive
value digits. Few candidates achieved all the marks
Output of correct sign here but many did spot the need to check if
value < 0 and convert the –ve to +ve or
change the sign. They were some
interesting ways of converting (not all
correct) ‐ve to+ve e.g. value = value ‐
(2*value).
Total 9
© OCR 2019. 9 of 9 PhysicsAndMathsTutor.com
Powered by TCPDF (www.tcpdf.org)