Question 3

OCR Computer Science November 2020 Paper 2GCSE26 marks

On the specification

(a)(i)
2.3 Producing robust programs
(a)(ii)
2.3 Producing robust programs
(a)(iii)
2.3 Producing robust programs
(b)(i)
2.2 Programming techniques
(b)(ii)
2.2 Programming techniques
(c)
2.1 Algorithms
(d)(i)
2.3 Producing robust programs
(d)(ii)
2.3 Producing robust programs
(e)
2.2 Programming techniques
(f)
2.2 Programming techniques
Question text

3 A vending machine has the following options available. Item code Item name Price A1 Crisps, bacon flavour £0.75 A2 Crisps, salted £0.75 B1 Chocolate bar £0.90 C1 Apple pieces £0.50 C2 Raisins £0.85 Users insert coins into the vending machine and then enter the two character item code of their selection. If the user has inserted enough money, the vending machine will release the chosen item and output any change required. If the user enters an invalid item code then a suitable error message is displayed. (a) The vending machine is tested before it is released. (i) Explain the purpose of testing the vending machine. [2] (ii) Describe the difference between iterative testing and final testing. [2] (iii) Complete the following test plan for the vending machine. Code entered Money inserted Expected result B1 £1 Chocolate bar served, £0.10 change given £0.85 Raisins served, no change given C1 Error – not enough money inserted C3 £0.75 [3] (b) The algorithm for one section of the vending machine program is shown in pseudocode. if money >= price then venditem() giveChange(money – price) else print("Error – not enough money inserted") endif (i) Give the identifier of one variable used in the algorithm. [1] (ii) State how many parameters are passed into the giveChange() subroutine. [1] (c) Draw the vending machine algorithm in part (b) as a flowchart. [5] (d) When writing the program for the vending machine, maintainability was considered. (i) Identify two ways that the program in part (b) has been made more maintainable. 1 2 [2] (ii) Give one additional way that the maintainability of the program can be improved. [1] (e) The vending machine stores the quantity of items available in a database table called ITEMS. The current contents of ITEMS is shown: ItemCode ItemName Stock A1 Crisps, bacon flavour 6 A2 Crisps, salted 2 B1 Chocolate bar 12 C1 Apple pieces 18 C2 Raisins 7 Complete the following SQL statement to display the item code for all items that have fewer than 10 in stock. SELECT FROM [4] (f) The vending machine can be in one of three states: on, off or suspended. A user can change the state of the vending machine by using the following algorithm. newstate = input("Enter the new state : ") switch newstate: case "on": statevalue = 1 case "off": statevalue = 2 case "suspended": statevalue = 3 default: print("Invalid state") endswitch Rewrite the algorithm to perform the same actions using IF statements in place of the switch statement. [5]