Question 1(b)(i) 2021 · May-June · Paper 43 · 4 marks
Reveal official mark-scheme answer
Official answer for Question 1
Part (b)
(i)
Question 1
mark per bullet point to max 4
Question 4
- Class declaration and end
- Private Items declared as array with 4 elements of type foodItem
- Private moneyIn declared as real and initialised to 0 in constructor
- Constructor heading taking 4 parameters and end …
- … assigning parameters to all 4 array values
Show text version of question
Question 1
Part (b)
(i)
Question 1
A vending machine allows users to insert coins to purchase an item.
The user then enters the code for the item they would like the machine to dispense (give out). The user must re-enter the code until it is valid.
If the code is valid but the user has not inserted enough money for the item chosen, the machine waits for more coins to be inserted. The user then has to re-enter the code.
The user can press cancel at any time to return the money inserted into the machine. The vending machine is part of a program that is written using object-oriented programming (OOP). The vending machine makes use of two classes that are described in the following tables.
All attributes are declared as private.
foodItem
name : STRING // the name of the item of food
code : STRING // the code to be entered for that item to be // selected
cost : REAL // the cost of the item constructor(nameP, codeP, // creates an instance of foodItem costP) // takes the name, code and cost as parameters
getCode() // returns the code for the item getCost() // returns the cost of the item getName() // returns the name of the item
vendingMachine
items : ARRAY[0:3] OF foodItem // stores four items of type foodItem moneyIn : REAL // stores the total money inserted by the // user, initialised to 0 in the constructor constructor(item1, item2, // creates an instance of vendingMachine, item3, item4) // takes four objects of type foodItem as // parameters and stores them in array items
insertMoney() // takes the value of the coin as a parameter // and adds it to moneyIn checkValid () // takes a code as a parameter and checks it is // valid against the food item codes getItemName() // takes the array index as a parameter and // returns the name of the food items
Question 4
(i)
Write program code to declare the class vendingMachine. You are only required to
write program code for the attribute declarations and the constructor.
If you are writing in Python, include attribute declarations using comments.
Use your programming language’s constructor method.
Programming language .....................................................................................................
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.....................................................................................................................................
Question 5
Why this question appears here
98% assigned-topic match · Further programming › Programming paradigms
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_43.pdf
