Past-paper question · 2021 May-June · Paper 41 · Q1(b)(iii)

Question 1(b)(iii) 2021 · May-June · Paper 41 · 2 marks

Original past-paper question for 1(B)(III)
Original past-paper question for 1(B)(III)
Original past-paper question for 1(B)(III)
Original past-paper question for 1(B)(III)
Original past-paper question for 1(B)(III)
Reveal official mark-scheme answer Official mark-scheme answer for 1(B)(III)

Official answer for Question 1

Part (b)

(iii)

Question 1

mark per bullet point to max 2

Question 2

  • Declaration of new instance of vendingMachine with identifier machineOne …
  • …passing all four objects as parameters using constructor
✓
Example code:
✓
VB.NET
✓
Dim machineOne as vendingMachine
✓
machineOne = new vendingMachine(chocolate, sweets, sandwich, apple)
✓
Python
✓
machineOne = vendingMachine(chocolate, sweets, sandwich, apple)
✓
Pascal
✓
machineOne := vendingMachine.Create(chocolate, sweets, sandwich, apple);
✓
9608/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_41.pdf →

Show text version of question

Question 1

Part (b)

(iii)

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

(iii)

Four objects of type foodItem are declared with the identifiers:

chocolate, sweets, sandwich, apple

Write program code to declare an instance of vendingMachine with the identifier machineOne and the objects: chocolate, sweets, sandwich, apple.

Programming language .....................................................................................................

Program code

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.....................................................................................................................................

[2]

Question 6

Topic relevance

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_41.pdf

Keep practising this topic