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

Question 1(b)(vi) 2016 · October-November · Paper 42 · 12 marks

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

Official answer for Question 1

Part (b)

(vi)

(vi)

1 mark per bullet to max 12

[12]
  • read NewInput from keyboard
  • check if input ‘C’ and state = Counting
✓
o then set state to cancelled
✓
o call method returnCoins() and set state to Idle
  • check if input ‘A’
✓
o then check if amount = 0 then output no coins
✓
o else set state to Accepted
✓
o call PrintTicket method and Set state to Idle
  • else if input is a valid coin
✓
o call CoinInserted method with NewInput as parameter
✓
o set state to Counting
✓
o error message if not a valid coin
✓
e.g.
✓
PYTHON:
✓
def stateChange(self):
✓
newInput = input("Insert coin: ")
✓
if newInput == "C":
✓
if self.__state == "Counting":
✓
self.setState("Cancelled")
✓
self.returnCoins()
✓
self.setState("Idle")
✓
elif newInput == "A":
✓
if self.__amount == 0:
✓
print("no coins inserted")
✓
else:
✓
self.setState("Accepted")
✓
self.__PrintTicket()
✓
self.setState("Idle")
✓
elif self.__validCoin(newInput):
✓
self.coinInserted(newInput)
✓
self.setState("Counting")
✓
else:
✓
print("Error - not a valid coin")
✓
PASCAL/DELPHI:
✓
procedure TicketMachine.StateChange();
✓
var
✓
NewInput : string;
✓
begin
✓
Write('Insert coin: ');
✓
Readln(NewInput);
✓
if (NewInput = 'C') then
✓
begin
✓
if (State = 'Counting') then
✓
begin
✓
State := 'Cancelled';
✓
ReturnCoins();
✓
end;
✓
SetState('Idle')
✓
end
✓
else
✓
if (NewInput = 'A') then
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International A Level – October/November 2016
✓
9608

Question 42

✓
begin
✓
if (Amount = 0) then
✓
Writeln('No coins inserted')
✓
else
✓
begin
✓
SetState('Accepted');
✓
PrintTicket();
✓
end;
✓
SetState('Idle');
✓
end
✓
else
✓
if (ValidCoin(NewInput)) then
✓
begin
✓
CoinInserted(NewInput);
✓
SetState('Counting')
✓
end
✓
else
✓
Writeln('Error - not a valid coin')
✓
end;
✓
VB:
✓
Public Sub StateChange()
✓
Dim NewInput As String
✓
NewInput = Console.Readline()
✓
If NewInput = “C” Then
✓
If State = “Counting” Then
✓
SetState(“Cancelled”)
✓
ReturnCoins()
✓
End If
✓
SetState(“Idle”)
✓
Elseif NewInput = “A” Then
✓
If Amount = 0 Then
✓
Console.Writeline(“No coins inserted”)
✓
Else
✓
SetState(“Accepted”)
✓
PrintTicket()
✓
Endif
✓
SetState(“Idle”)
✓
Elseif ValidCoin(NewInput) Then
✓
CoinInserted(NewInput)
✓
SetState(“Counting”)
✓
Else
✓
Console.Writeline(“Error – not a valid coin”)
✓
EndIf
✓
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)

(vi)

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

(vi)

Convert the flowchart to program code for the method StateChange().

Use the attributes and methods in the original class definition and the ValidCoin() function from part (iv).

METHOD StateChange

INPUT NewInput

Yes Is State = Yes Is NewInput = 'C'? CALL SetState("Cancelled") "Counting"?

No CALL ReturnCoins() No

Is NewInput = 'A'? Yes Yes OUTPUT "No Is Amount = 0? coins inserted"

No No

CALL SetState("Accepted") CALL PrintTicket()

Is NewInput Yes CALL CoinInserted(NewInput) a valid coin? No CALL SetState("Counting") CALL SetState("Idle")

OUTPUT "Error – not a valid coin"

ENDMETHOD

Question 7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.....................................................................................................................................[12]

Question 8

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