Practise Variables, constants and data structures (strings, arrays and records). 12 exam-style questions on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
(c) Explain one benefit of using a constant for the VAT rate instead of writing 0.2 wherever it is needed.[2]
Show the answer and mark scheme
(a)Answer:VAT_RATE
VAT_RATE
(b)Answer:price
price / vat / total
(c)Answer: If the rate changes, only line 01 needs editing, so no occurrence of 0.2 can be missed (and the name makes the code clearer).
if the VAT rate changes, it only has to be changed in one place (line 01) / the meaningful name shows what the value is
so every part of the program uses the new value and none is missed / so the code is easier to read and maintain
Question 3Hard6 marks
A sports club stores details of its 200 members: each member's name, membership number, date of joining and whether they have paid this year's fee.
(a) Describe how the club could use records and an array to store these details.[4]
(b) Explain why storing the details in four separate arrays, one for each item, could cause problems.[2]
Show the answer and mark scheme
(a)Answer: One record per member with a field for each detail (string, integer, date, Boolean), and an array of 200 of these records that a loop can process.
each member's details are stored in one record
with one field for each item: name (string), membership number (integer), date of joining (string / date) and paid (Boolean)
the 200 records are stored in an array, one element for each member
so a loop can go through the array to process every member, e.g. to list the members who have not paid
each field is accessed by its name (or its position in the record), so the details of one member stay together
(b)Answer: A member's details are linked only by their index, so changing or sorting one array but not the others mixes up different members' details.
the details of one member are spread across four arrays and are only linked by being at the same index
if one array is sorted, or has an item added or removed, without the others being changed in the same way, the details become mismatched (they belong to the wrong member)