Past-paper question · 2021 May-June · Paper 43 · Q1(b)(i)

Question 1(b)(i) 2021 · May-June · Paper 43 · 4 marks

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

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
✓
Example code:
✓
VB.NET
✓
Public Class vendingMachine
✓
Private items(3) As foodItem
✓
Private moneyIn As Single
✓
Public Sub New(item1, item2, item3, item4)
✓
items(0) = item1
✓
items(1) = item2
✓
items(2) = item3
✓
items(3) = item4
✓
moneyIn = 0
✓
End Sub
✓
End Class
✓
Python
✓
class vendingMachine:
✓
#private items(4) of type foodItem
✓
#private moneyIn of type Real
✓
def __init__(self, item1, item2, item3, item4):
✓
self.__items = []
✓
self.__items.append(item1)
✓
self.__items.append(item2)
✓
self.__items.append(item3)
✓
self.__items.append(item4)
✓
self.__moneyIn = 0
✓
9608/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_43.pdf →

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

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

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

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

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

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

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

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

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

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

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

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

[4]

Question 5

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

Keep practising this topic