Past-paper question · 2016 October-November · Paper 43 · Q1(b)(v)

Question 1(b)(v) 2016 · October-November · Paper 43 · 4 marks

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

Official answer for Question 1

Part (b)

(v)

(v)

1 mark per bullet to max 4

[4]
  • function header taking string parameter, returns Boolean
  • check length of string is 4
  • check each character is a digit
  • return of correct Boolean value for both cases
✓
e.g
✓
PYTHON:
✓
def __valid(self, s):
✓
digits = ['0','1','2','3','4','5','6','7','8','9']
✓
isValid = False
✓
if (len(s) == 4):
✓
if (s[0] in digits) & (s[1] in digits) & (s[2] in digits) &
✓
(s[3] in digits):
✓
isValid = True
✓
return(isValid)
✓
PASCAL/DELPHI:
✓
function Valid(s : string) : Boolean;
✓
var isValid : Boolean; i : integer;
✓
begin
✓
isValid := False
✓
if Length(s) = 4
✓
then
✓
begin
✓
isValid := True;
✓
For i := 1 to 4 do
✓
if (s[i] < '0') OR (s[i] > '9')
✓
then
✓
isValid := False;
✓
end;
✓
end;
✓
VB: ByVal optional
✓
Public Function valid(ByVal s As String) As Boolean
✓
If s Like "####" Then
✓
Return True
✓
Else
✓
Return False
✓
End If
✓
End Function
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International A Level – October/November 2016
✓
9608

Question 43

Mark scheme 9608_w16_ms_43.pdf →

Show text version of question

Question 1

Part (b)

(v)

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

(v)

The user must enter a 4-digit code.

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

  • TRUE if the input string s consists of exactly 4 digits
  • FALSE otherwise

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

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

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

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

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

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

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

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

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

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

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

[4]

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

Keep practising this topic