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

Question 1(b)(vi) 2016 · October-November · Paper 41 · 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 Chars from keyboard
  • check if ‘R’ and state = Open-CodeSet
  • call method Reset() & method SetState
  • if Chars is the set code:
  • check if locked
  • set state to Open-CodeSet
  • else if closed
  • then set state to Locked
  • if Chars is empty and State is “Open-CodeSet” then setState to closed
  • if Chars is a valid 4-digit code and state is Open-NoCode
  • call setNewCode and SetState
  • outputting correct error messages for not valid 4-digit and state is not Open-NoCode
✓
e.g.
✓
PYTHON:
✓
def StateChange(self):
✓
Chars = input("Enter code: ")
✓
if Chars == "R":
✓
if self.__state == "Open-CodeSet":
✓
self.reset()
✓
self.SetState("Open-NoCode")
✓
elif Chars == self.__code:
✓
if self.__state == "Locked":
✓
self.SetState("Open-CodeSet")
✓
elif self.__state == "Closed":
✓
self.SetState("Locked")
✓
elif (Chars == "")
✓
& (self.__state == "Open-CodeSet"):
✓
self.SetState("Closed")
✓
elif self.__valid(Chars):
✓
if self.__state == "Open-NoCode":
✓
self.SetNewCode(Chars)
✓
self.SetState("Open-CodeSet")
✓
else:
✓
print("Error - does not match set code")
✓
else:
✓
print("Error - Code format incorrect")
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International A Level – October/November 2016
✓
9608

Question 41

✓
PASCAL/DELPHI:
✓
Procedure StateChange();
✓
var Chars : String;
✓
begin
✓
ReadLn(Chars);
✓
If Chars = 'R' Then
✓
If State = 'Open-CodeSet' Then
✓
begin
✓
Reset();
✓
SetState('Open-NoCode');
✓
end
✓
Else
✓
If Chars = Code Then
✓
If state = 'Locked' Then
✓
SetState('Open-CodeSet')
✓
Else
✓
If state = 'Closed' Then
✓
SetState('Locked')
✓
Else
✓
If (Chars = '') AND (State = 'Open-CodeSet') Then
✓
SetState('Closed')
✓
Else
✓
If Valid(Chars) Then
✓
begin
✓
If State == 'Open-NoCode' Then
✓
begin
✓
SetNewCode(Chars);
✓
SetState('Open-CodeSet');
✓
end
✓
else
✓
WriteLn('Error - does not match set code')
✓
end
✓
Else
✓
WriteLn('Error - Code format incorrect');
✓
end;
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International A Level – October/November 2016
✓
9608

Question 41

✓
VB:
✓
Public Sub StateChange()
✓
Dim Chars As String
✓
Chars = Console.ReadLine()
✓
If Chars = "R" Then
✓
If State = "Open-CodeSet" Then
✓
Reset()
✓
SetState("Open-NoCode")
✓
End If
✓
ElseIf Chars = Code Then
✓
If state = "Locked" Then
✓
SetState("Open-CodeSet")
✓
ElseIf state = "Closed" Then
✓
SetState("Locked")
✓
End If
✓
ElseIf (Chars = "") AND (State = "Open-CodeSet") Then
✓
SetState("Closed")
✓
ElseIf Valid(Chars) Then
✓
If State == "Open-NoCode" Then
✓
SetNewCode(Chars)
✓
SetState("Open-CodeSet")
✓
Else
✓
Console.WriteLine("Error - does not match set code")
✓
End If
✓
Else
✓
Console.WriteLine("Error - Code format incorrect")
✓
End If
✓
End Sub

Mark scheme 9608_w16_ms_41.pdf →

Show text version of question

Question 1

Part (b)

(vi)

Question 1

A user can lock a safety deposit box by inputting a 4-digit code. The user can unlock the box with

the same 4-digit code.

There is a keypad on the door of the safety deposit box. The following diagram shows the keys on the keypad.

1 2 3

4 5 6

7 8 9

R 0 Enter

Initially, the safety deposit box door is open and the user has not set a code.

The operation of the safety deposit box is as follows:

A) To set a new code the door must be open. The user chooses a 4-digit code and sets it by pressing the numerical keys on the keypad, followed by the Enter key. Until the user clears this code, it remains the same. (See point E below) B) The user can only close the door if the user has set a code. C) To lock the door, the user closes the door, enters the set code and presses the Enter key. D) To unlock the door, the user enters the set code. The door then opens automatically. E) The user clears the code by opening the door and pressing the R key, followed by the Enter key. The user can then set a new code. (See point A above)

The following state transition table shows the transition from one state to another of the safety deposit box:

Current state Event Next state Door open, no code set 4-digit code entered Door open, code set Door open, code set R entered Door open, no code set Door open, code set Close door Door closed Door closed Set code entered Door locked Door locked Set code entered Door open, code set Door locked R entered Door locked

Question 3

A
company wants to simulate the use of a safety deposit box. It will do this with object-oriented

programming (OOP).

The following diagram shows the design for the class SafetyDepositBox. This includes the properties and methods.

SafetyDepositBox Code : STRING // 4 digits State : STRING // "Open-NoCode", "Open-CodeSet", "Closed" // or "Locked" Create() // method to create and initialise an object // if using Python use __init__ Reset() // clears Code SetState() // set state to parameter value // and output new state SetNewCode() // sets Code to parameter value // output message and new code StateChange() // reads keypad and takes appropriate action

Write program code for the following methods.

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

(vi)

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

properties and methods in the original class definition and the Valid() function from part (v).

METHOD StateChange

INPUT Chars

Yes Is State = Yes Is Chars = 'R'? CALL Reset() "Open-CodeSet"?

No No CALL SetState("Open-NoCode")

Is Chars = Code? Yes Is State = Yes CALL SetState("Open-CodeSet") "Locked"?

No No

Is State = Yes CALL SetState("Locked") "Closed"?

No

Is Chars = "" Yes and State = CALL SetState("Closed") "Open-CodeSet"?

No

Yes Is State = Yes Is Chars a valid CALL SetNewCode(Chars) 4-digit code? "Open-NoCode"?

No No CALL SetState("Open-CodeSet") OUTPUT "Error – OUTPUT "Error – code format does not match incorrect" set code"

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

Keep practising this topic