Past-paper question · 2016 October-November · Paper 42 · Q1(b)(iv)

Question 1(b)(iv) 2016 · October-November · Paper 42 · 3 marks

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

Official answer for Question 1

Part (b)

(iv)

(iv)

1 mark per bullet to max 3:

[3]
  • function header, take string as parameter, return Boolean
  • check the parameter is a valid coin
  • return of value for both cases
✓
e.g.
✓
PYTHON:
✓
def __validCoin(self, s):
✓
coins = ['10','20','50','100']
✓
if s in coins:
✓
isValid = True
✓
else:
✓
isValid = False
✓
return(isValid)
✓
PASCAL/DELPHI:
✓
function TicketMachine.ValidCoin(s : string) : boolean;
✓
begin
✓
if ((s = '10') or (s = '20') or (s = '50') or (s = '100'))
✓
then
✓
ValidCoin:= True;
✓
else
✓
ValidCoin := False;
✓
end;
✓
VB:
✓
Public Function ValidCoin(ByVal s As String) As Boolean
✓
If s = “10” or s = “20” or s = “50” or s = “100” Then
✓
ValidCoin = True
✓
Else
✓
ValidCoin = False
✓
End If
✓
End Sub
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International A Level – October/November 2016
✓
9608

Question 42

Mark scheme 9608_w16_ms_42.pdf →

Show text version of question

Question 1

Part (b)

(iv)

Question 1

The ticket machine in the following diagram accepts the following coins: 10, 20, 50 and 100 cents.

The ticket machine has:

  • a slot to insert coins
  • a tray to return coins
  • a ticket dispenser
  • two buttons:
  • button A (Accept)
  • button C (Cancel)

$ Coin Slot

&

Coin return Ticket dispenser tray

When the user has inserted as many coins as required, they press button A to print the ticket.

To cancel the transaction, the user can press button C. This makes the machine return the coins.

Invalid coins have no effect.

Question 3

The following state transition table shows the transition from one state to another of the ticket machine:

Current state Event Next state Idle Coin inserted Counting Counting Coin inserted Counting Counting Button C pressed Cancelled Cancelled Coins returned Idle Counting Button A pressed Accepted Accepted Ticket printed Idle

A
company wants to simulate the use of a ticket machine. It will do this with object-oriented

programming (OOP).

The following diagram shows the design for the class TicketMachine. This includes its attributes and methods.

TicketMachine Amount : INTEGER // total value of coins inserted in cents State : STRING // "Idle", "Counting", "Cancelled" // or "Accepted" Create() // method to create and initialise an object // if using Python use __init__ SetState() // set state to parameter value // and output new state StateChange() // insert coin or press button, // then take appropriate action CoinInserted() // parameter is a string // change parameter to integer // and add coin value to Amount ReturnCoins() // output Amount, then set Amount to zero PrintTicket() // print ticket, then set Amount to zero

Write program code for the following methods.

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

(iv)

Each coin inserted must be one of the following: 10, 20, 50 or 100 cents.

Write program code for a function ValidCoin(s : STRING) that returns:

  • TRUE if the input string is one of "10", "20", "50" or "100"
  • FALSE otherwise

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

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

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

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

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

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

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

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

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

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

.......................................................................................................................................[3]

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

Keep practising this topic