Algorithm design methods: decision tables, JSP and state-transition diagrams – A Level Computer Science (old syllabus, to 2021) (9608)
10 questions · Clear filters
Question text
2
A grade generator program takes the mark a student obtained in a test as input.
The program calculates and outputs the grade that matches the mark. The grade is either A, B, C,
D or U.
Complete the following JSP structure diagram for the grade generator program.
GradeGenerator
[4]
Question text
2
Complete the JSP structure diagram for the following pseudocode procedure.
PROCEDURE Calculate()
INPUT Number1
INPUT Number2
INPUT Command
IF Command = 1
THEN
Function1(Number1, Number2)
Value
ELSE
IF Command = 2
THEN
Function2(Number1, Number2)
Value
ELSE
Function3(Number1, Number2)
Value
ENDIF
ENDIF
OUTPUT Value
ENDPROCEDURE
JSP structure diagram
Calculate
[4]
Question text
3
A user has to choose a new password to create an account. It is recommended that the password
has at least two of the following elements:
•
upper-case letter
•
numeric character
•
symbol.
The system outputs:
•
"Strong" if there are at least two of the elements
•
"Medium" if there is only one of the elements
•
"Weak" if there are none of the elements.
Complete the following decision table for the password system described.
Rules
One or more
upper-case
N
Y
N
Y
N
Y
N
Y
letters
One or more
Conditions
numeric
N
N
Y
Y
N
N
Y
Y
characters
One or more
N
N
N
N
Y
Y
Y
Y
symbols
Strong
Actions
Medium
Weak
[3]
Question text
12 ENDFUNCTION
(a) State the line number in the pseudocode algorithm that shows function NumberPattern()
is recursive. Justify your choice.
Line number …
Justification …
…
…
[2]
(b) The function is called as follows:
NumberPattern(1,1,12)
Dry run the algorithm and complete the following trace table. State the final value returned.
Show your working.
Value1
Value2
Temp
EndValue
OUTPUT
RETURN value
Final value returned …
Working
…
…
…
…
…
…
…
[5]
(c) State the purpose of the algorithm.
…
… [1]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of
Question text
4
A bank wants to analyse how an automated teller machine (ATM) deals with transactions.
The following state-transition table shows the transitions from one state to another for a transaction.
Current state
Event
Next state
ATM active
Insert card
Waiting for PIN
Waiting for PIN
Enter PIN
Checking PIN
Waiting for PIN
Cancel selected
Transaction cancelled
Checking PIN
PIN valid
Account accessed
Checking PIN
PIN invalid
Waiting for PIN
Account accessed
Cancel selected
Transaction cancelled
Account accessed
Input amount to withdraw
Checking account
Checking account
Funds available
Transaction complete
Transaction complete
Return card and dispense cash
ATM active
Checking account
Funds not available
Account accessed
Transaction cancelled
Return card
ATM active
Complete the state-transition diagram to correspond with the table.
Insert card
Start
ATM
Waiting
active
for PIN
Enter PIN
Transaction
Transaction
Checking
complete
cancelled
PIN
Checking
Account
account
accessed
Input amount to withdraw
[8]
Question text
1
A bank provides bank accounts to customers.
The following pseudocode represents the operation of the bank account.
CALL OpenAccount()
CALL AccountLifeTime()
CALL CloseAccount()
PROCEDURE AccountLifeTime()
REPEAT
CALL Transactions()
UNTIL AccountClosed() = TRUE
ENDPROCEDURE
PROCEDURE CloseAccount()
IF ReopenAccount() = TRUE
THEN
CALL FlagToReopen()
ELSE
CALL DeletePermanently()
ENDIF
ENDPROCEDURE
(a) Complete the JSP structure diagram for this bank account from the pseudocode given.
Bank account
[6]
(b) A transaction can be a credit (deposit) or a debit (withdrawal).
There are two types of transaction that are credits (deposits). These are:
•
SWIFT payment
•
BACS payment
There are three types of transaction that are debits (withdrawals). These are:
•
Debit card payment
•
Cheque payment
•
Online payment
Complete the JSP structure diagram to represent these additional requirements.
Transaction
[4]
Question text
1
A greenhouse has a window that automatically opens and closes depending on the internal
temperature.
If the temperature rises above 20 °C, the window half opens. If the temperature rises above 30 °C,
the window fully opens. If the temperature drops below 25 °C, the window returns to being half
open. If the temperature drops below 15 °C, the window fully closes.
The window has three possible states: Closed, Half Open and Fully Open.
Current state
Event
Next state
Closed
Temperature rises above 20 °C
Half Open
Half Open
Temperature drops below 15 °C
Closed
Half Open
Temperature rises above 30 °C
Fully Open
Fully Open
Temperature drops below 25 °C
Half Open
Complete the state-transition diagram for the window:
…
…
…
…
…
…
…
…
…
…
…
…
…
…
[7]
Question text
2
(a) (i)
State how repetition is shown in a Jackson Structured Programming (JSP) structure
diagram.
…
… [1]
(ii)
State how selection is shown in a JSP structure diagram.
…
… [1]
(b) A simple calculator is to be created.
The calculator is to be used as follows:
User inputs 2 numbers (x and y).
•
User inputs an operator (+, –, * or / ).
•
The calculator computes the answer.
•
The calculator displays the answer.
•
Draw a JSP diagram for the calculator. The first element is provided.
Calculator
[5]
Question text
1
Students are choosing their A Level subjects based on their IGCSE subject results.
A student can take:
•
Computer Science, if they have a grade C in Maths or a grade C in Computer Science
•
Maths, if they have a grade C in Maths
•
Physics, if they have a grade C in Science and a grade C in Maths.
(a) Complete the decision table.
Column
1
2
3
4
5
6
7
8
Grade C in
Y
Y
Y
Y
N
N
N
N
Conditions
Computer Science
Grade C in Maths
Y
Y
N
N
Y
Y
N
N
Grade C in Science
Y
N
Y
N
Y
N
Y
N
Take Computer
Science
Actions
Take Maths
Take Physics
[4]
(b) Simplify your solution by removing redundancies.
Column
S
T
U
V
W
X
Y
Z
Grade C in
Conditions
Computer Science
Grade C in Maths
Grade C in Science
Take Computer
Science
Actions
Take Maths
Take Physics
[3]
(c) Show how the columns from part (a) were simplified to create the columns in part (b).
For example, if columns 5, 6 and 7 were simplified to create column X, then you state this in
your answer.
…
…
…
…
…
… [3]
Question text
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
Ticket dispenser
return
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.
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) Complete the state-transition diagram.
start
Coin inserted
…
…
…
Cancelled
Coins returned
…
…
…
…
[7]
(b) 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 …
Create()
(i)
…
…
…
…
… [3]
SetState()
(ii)
…
…
…
… [2]
ReturnCoins()
(iii)
…
…
…
…