0% found this document useful (0 votes)
2 views

Cec223compalgorithm Solved Exsamples

The document outlines algorithms for various problems including lift control, temperature regulation, toll gate operation, scoring in a squash-like game, record separation for a database, and a number guessing game. Each problem is accompanied by pseudocode and flowcharts that illustrate the logic and structure of the solutions. The algorithms utilize various programming constructs such as sequence, repeat-until, while, case, and subprograms.

Uploaded by

gts930361
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Cec223compalgorithm Solved Exsamples

The document outlines algorithms for various problems including lift control, temperature regulation, toll gate operation, scoring in a squash-like game, record separation for a database, and a number guessing game. Each problem is accompanied by pseudocode and flowcharts that illustrate the logic and structure of the solutions. The algorithms utilize various programming constructs such as sequence, repeat-until, while, case, and subprograms.

Uploaded by

gts930361
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Lift Problem

Problem A lift remains positioned at the ground floor level of a


building with the doors shut whenever it is not in use.
When a call button is pressed on any floor, the lift moves
to the required floor and the lift doors open. Write an
algorithm to express the logic of controlling the lift.

Solution 1 This solution uses sequence and repeat-until structures.

Pseudocode
An algorithm to express the logic of controlling a lift
BEGIN MAINPROGRAM
REPEAT
check all buttons
UNTIL a button is pressed
move to the required floor
open the doors
END MAINPROGRAM

Flowchart
An algorithm to express the logic of controlling a lift

begin

check all buttons

False button is
pressed

True

move to the
required floor

open the doors

end

31
Methods of Algorithm Description

Solution 2 This solution uses sequence and while structures.

Pseudocode
An algorithm to express the logic of controlling a lift
BEGIN MAINPROGRAM
check all buttons
WHILE no button has been pressed
check all buttons
ENDWHILE
move to the required floor
open the doors
END MAINPROGRAM

Flowchart
An algorithm to express the logic of controlling a lift

begin

check all buttons

no button False
is pressed

True

check all buttons

move to the
required floor

open the doors

end

32
Temperature Control Problem
Problem At a NSW coastal town the maximum annual temperature
range is typically 12–34 degrees Celsius. An air
conditioning company is installing a heating/cooling
system in a new shopping centre in that town. The system
checks the temperature every five minutes and adjusts the
air temperature by using a combination of two heating
and two cooling units. These units operate according to
these temperature ranges:
0–15 degrees C – 2 heating units
16–20 degrees C – 1 heating unit
21–28 degrees C – 1 cooling unit
> 29 degrees C – 2 cooling units
Write an algorithm that could be used to control the air
conditioning system.

Solution This solution uses sequence, while and case structures.

Pseudocode
An algorithm to describe the control of an air conditioning
system. The input comes from sensors in the shopping
centre.
BEGIN MAINPROGRAM
read the temperature
WHILE the system is turned on
CASEWHERE temperature
< 16 : run two heating units
16 to 20 : run one heating unit
21 to 28 : run one cooling unit
OTHERWISE : run two cooling units
ENDCASE
wait five minutes
read the temperature
ENDWHILE
END MAINPROGRAM

33
Methods of Algorithm Description

Flowchart
An algorithm to describe the control of an air conditioning
system. The input comes from sensors in the shopping
centre.

begin

read the
temperature

system False
turned on

True

temperature
range is

less than 16 16–20 21–28 otherwise

run two run one run one run two


heating units heating unit cooling unit cooling units

wait five
minutes

read the
temperature

end

34
Toll Gate Problem
Problem When operational a toll gate operates by having a boom
gate obstructing the road, and a sensor detecting when a
vehicle is present. After coins to the value of $1.00 have
been deposited in the basket, the boom gate opens and
stays open until a vehicle has gone through. Amounts
greater than $1.00 are accepted but no change is given.
Individual coins less than 10 cents are ignored.
Write an algorithm to describe the control of the toll gate.

Solution This solution uses sequence, if-then, repeat-until, while, and


subprogram structures.

Pseudocode
An algorithm used to describe the operation of a toll gate
that has a boom gate, a vehicle sensor, and a coin
collection basket.

BEGIN MAINPROGRAM
REPEAT
REPEAT
wait
UNTIL car has arrived
get the money
open boom gate
REPEAT
wait
UNTIL car has passed
close boom gate
UNTIL toll gate is not operational
END MAINPROGRAM

BEGIN SUBPROGRAM get the money


INITIALISATION
money collected is set to 0
END INITIALISATION
WHILE money collected is less than $1
receive coin
IF coin is less than 10 cents THEN
ignore coin
ELSE
add the value of the coin to the money collected
ENDIF
ENDWHILE
END SUBPROGRAM get the money

35
Methods of Algorithm Description

Flowchart
An algorithm used to describe the operation of a toll gate
that has a boom gate, a vehicle sensor, and a coin collection
basket.

begin

wait

False car has


arrived

True

get the money

open boom gate

wait

False car has


passed

True

close boom gate

False toll gate not


operational

True

end

36
Methods of Algorithm Description

Subprogram

begin
get the money

set money
collected to zero

money False
collected less
than $1

True

receive a coin

False coin True


smaller
than 10c

add value of
coin to money ignore coin
collected

end
get the money

37
‘Squash’ Scoring Problem
Problem Write an algorithm to describe how to score a ball game,
which is similar to squash. This ball game is scored as
follows: the server gets one point for winning a rally. If
the server loses the rally they lose the right to serve the
next ball, but lose no points. The receiver gains the right
to serve (but no point) if they win a rally. To win the game
a player must win nine points.

Solution This solution uses sequence, repeat-until, if-then and subprogram


structures.

Pseudocode
An algorithm to describe the logic for scoring a ball game
similar to squash.

BEGIN MAINPROGRAM
INITIALISATION
set RequiredPoints to 9
set each player’s points to 0
END INITIALISATION
toss and decide the server
REPEAT
server serves the ball
REPEAT
play the rally
UNTIL rally is won
IF the server wins the rally THEN
increment the server’s points by 1
ELSE
swap player status
ENDIF
UNTIL a player has won RequiredPoints
declare the winner
END MAINPROGRAM

BEGIN SUBPROGRAM toss and decide the server


toss a coin
IF heads THEN
player 1 is the server
player 2 is the receiver
ELSE
player 2 is the server
player 1 is the receiver
ENDIF
END SUBPROGRAM toss and decide the server

38
Methods of Algorithm Description

Flowchart
An algorithm to describe the logic for scoring a ball game
similar to squash.

begin

set RequiredPoints
to 9

set each player’s


score to 0

toss and
decide server

server serves
the ball

play a rally

False
rally won

True

False server wins True


the rally

swap the increase server's


player status points by one

False player has


RequiredPoints

True

end

39
Methods of Algorithm Description

Subprogram

begin toss and


decide server

toss a coin

False result True


is heads

player 2 is player 1 is
the server the server

player 1 is player 2 is
the receiver the receiver

end toss and


decide server

40
Record Separation Problem
Problem Let us assume that a particular database program
manages a simple mailing list which consists of one record
for each person on the list, and a number of fields
containing information about each person (their name,
address, etc). The program can read in data produced by a
word processor provided that data is structured in the
following way:
Each record to be read must be a single paragraph
terminated by a return character, and each field within a
record is separated by a tab character. For example:
Colin Jamesontab33 Falcon StreettabWaverlytabNSWtab2113return

would be read as one record containing five fields. The


end of the data is marked with a # (hash) character which
immediately follows the return ending the last paragraph.
Assuming that there is at least one line of valid data at the
start of the input file, describe an algorithm that the
program might use to read such data one character at a
time and place the information into separate fields and
records. The algorithm reports the number of records read
when all the records have been processed.

41
Methods of Algorithm Description

Solution 1 This solution uses sequence, while and case structures.

Pseudocode
An algorithm to describe the separation of a string of
formatted data into fields and records to be used as input
to a database.

BEGIN MAINPROGRAM

INITIALISATION
set record number to 0
set field number to 0
set field to empty
END INITIALISATION

read a character from the input file

WHILE character is not a hash

CASEWHERE character is

tab: output the field to the database


increment the field number
set the field to empty

return: output the field to the database


increment the field number
increment the record number
set field number to 0
set the field to empty

OTHERWISE: append the character to the field

ENDCASE

read a character from the input file

ENDWHILE

report how many records were read

END MAINPROGRAM

42
Methods of Algorithm Description

Flowchart
An algorithm to describe the separation of a string of
formatted data into fields and records to be used as input
to a database.

begin

record number and


field number are set
to 0
field is set to empty

read a character
from input file

character False
not a hash

True

character is

tab return otherwise

append character
output the field output the field to the field

increment the increment the


field number field number

increment the
set field to empty record number

set field number


to 0 and field
to empty

read a character
from input file

report how many


records were read

end

43
Methods of Algorithm Description

Solution 2 This solution uses sequence, repeat-until and if-then-else


structures.

Pseudocode
An algorithm to describe the separation of a string of
formatted data into fields and records to be used as input
to a database.

BEGIN MAINPROGRAM

INITIALISATION
record number is set to 0
field number is set to 0
field is set to empty
END INITIALISATION

REPEAT
read a character from the file
IF the character is a hash THEN
don’t do anything
ELSE
IF the character is a return THEN
output the field to the database
increment the field number
increment the record number
set the field number to 0
set the field to empty
ELSE
IF the character is a tab THEN
output the field to the database
increment the field number
set the field to empty
ELSE
append the character to the field
ENDIF
ENDIF
ENDIF
UNTIL the character is a hash

report how many records were read

END MAINPROGRAM

44
Methods of Algorithm Description

Flowchart
An algorithm to describe the separation of a string of
formatted data into fields and records to be used as input
to a database.

begin

record number and


field number are set
to 0
field is set to empty

read a character
from input file

True character False


is a hash

True character False


is a return

output the field


to the database
True character False
is a tab
increment the field
number and output the field add the character
record number to the database to the field

set field number increment the


to 0 field number

set the field set the field


to empty to empty

False character
is a hash

True

report how many


records were read

end

45
Methods of Algorithm Description

Solution 3 This solution uses sequence and while structures.

Pseudocode
An algorithm to describe the separation of a string of
formatted data into fields and records, which are to be
used as input to a database. It assumes the data are correct.

MAINPROGRAM

INITIALISATION
set record number to 0
set field number to 0
set field to empty
END INITIALISATION
read a character from the file
WHILE the character is not a hash
WHILE the character is not a return
WHILE the character is not a tab
append the character to the field
read a character from the file
ENDWHILE
output the field to the database
increment the field number
set field to empty
read a character from the file
ENDWHILE
output the field to the database
increment the record number
set field number to 0
set the field to empty
read a character from the file
ENDWHILE
report how many records were read
END MAINPROGRAM

46
Methods of Algorithm Description

Flowchart
An algorithm to describe the separation of a string of
formatted data into fields and records, which are to be
used as input to a database. It assumes the data are correct.

begin

record number and


field number are set
to 0
field is set to empty

read a character
from the file

character False
not a hash

True

character False
not a return

True

character False
not a tab

True
add the character
to the file

read a character
from the file

output the field

increment the
field number

set field to empty

read a character
from the file

output the field

increment the
record number

set field to empty and


field number to 0

read a character
from the file

report number of
records read

end

47
Guess the Number Problem
Problem In a simple number game your opponent thinks of a secret
number between l and 100. In no more than 10 guesses
you have to try to guess the number. After each guess
your opponent tells you if your guess was too high, too
low or correct. Your opponent also keeps track of how
many guesses you have had and tells you the game is over
when you use all of your ten guesses or when you guess
the number correctly.
Describe an algorithm which takes the role of your
opponent in this game. Include in your solution a
subprogram which checks for illegal guesses (those less
than l or greater than 100). Include also the subprogram
which generates a secret number between 1 and 100. Do
not expand this but assume it is available.

48
Methods of Algorithm Description

Solution This solution uses sequence, repeat-until, if-then-else and


subprogram structures.

Pseudocode
An algorithm to describe a game in which the user tries to
guess a number between 1 and 100, using no more than
ten guesses.

BEGIN MAINPROGRAM
INITIALISATION
number of guesses is set to 0
GotIt is set to false
END INITIALISATION
generate a secret number using random number generator
REPEAT
get a guess from the user
IF the guess is in range THEN
increment the number of guesses
check the guess
ELSE
tell the user the guess is out of range
ENDIF
UNTIL guess is correct (GotIt is true) or number of guesses is 10
IF the guess is incorrect (GotIt is false) THEN
tell the user they have run out of guesses (=10)
tell the user the secret number
ENDIF
END MAINPROGRAM

BEGIN SUBPROGRAM check the guess


IF guess > secret number THEN
tell the user their guess is too big
ELSE
IF guess < secret number THEN
tell the user their guess is too small
ELSE
congratulate the user on a correct guess
tell them how many guesses they took
set GotIt to true
ENDIF
ENDIF
END SUBPROGRAM check the guess

49
Methods of Algorithm Description

Flowchart
An algorithm to describe a game in which the user tries to
guess a number between 1 and 100, using no more than
ten guesses.

begin

set the number


of guesses to 0
and GotIt to false

generate a secret
number using
random generator

get a guess
from the user

False guess in True


range

tell user that guess increment the


is out of range number of guesses

check the guess

GotIt is
False true or number
of guesses is
equal to 10

True

False GotIt True


is false

tell user they have


run out of guesses

tell the user the


secret number

end

50
Methods of Algorithm Description

Subprogram

begin
check the guess

guess is
True bigger than False
secret
number

tell the user the


guess is too big guess is
True less than False
secret
number
congratulate the
tell the user the user on guessing
guess is too small the secret number

tell the user how


many guesses
were taken

set GotIt to true

end
check the guess

51
Income Tax Problem
Problem To calculate the income tax payable on any income based
on the income tax scales shown below. The taxable income
is to be entered and the tax payable calculated.

Tax Scales

Taxable Income ($) Tax payable


$1–5400 Nil
$5401–20 700 Nil plus 20 cents for each $1 over $5400
$20 701–36 000 $3060 plus 38 cents for each $1 over $20 700
$36 001–50 000 $8874 plus 46 cents for each $1 over $36 000
$50 001 and over $15 314 plus 47 cents for each $1 over $50 000

Solution This solution uses sequence and if-then structures.

Pseudocode
An algorithm used to calculate the tax payable on any
income using taxation rates set in the given table.

BEGIN MAINPROGRAM
input income
IF income greater than or equal to 50 001 THEN
tax is 15 314 + (income – 50 000) * 0.47
ELSE
IF income greater than or equal to 36 001 THEN
tax is 8874 + (income – 36 000) * 0.46
ELSE
IF income greater than or equal to 20 701 THEN
tax is 3060 + (income – 20 700) * 0.38
ELSE
IF income greater than or equal to 5401 THEN
tax is (income – 5400) * 0.20
ELSE
tax is nil
ENDIF
ENDIF
ENDIF
ENDIF
display income and tax payable
END MAINPROGRAM

52
Methods of Algorithm Description

Flowchart
An algorithm used to calculate the tax payable on any
income using taxation rates set in the given table.

begin

read the income

True income is False



50 001

tax is 15 314 +
(income – 50 000)
* 0.47 True income is False

36 001
tax is 8874 +
(income – 36 000)
* 0.46 True income is False

20 701
tax is 3060 +
(income – 20 700)
* 0.38 True income is False

5401

tax is
(income – 5400) tax is nil
* 0.20

display income
and tax

end

Another valid method of solving this problem is to use the


multiple selection or ‘case’ structure.

53
Telephone Dialler Problem
Problem A telephone dialler is connected between a computer and
a telephone (see the diagram below). Its purpose is to dial
a telephone number entered via the computer keyboard,
establish a connection if it can and report on its progress
and degree of success. The whole telephone number is
entered via the computer keyboard at one time and is
stored in a buffer in the computer.

number pulses

Telephone
Dialler

message tones
(engaged,
answered etc)

The dialler ‘dials’ a digit by sending pulses along the


telephone line. To dial 2 it sends two pulses, to dial 5 it
sends five pulses etc. In the special case of a zero it sends
ten pulses. There is a gap of 2 seconds between the set of
pulses representing a digit of a telephone number.
The dialler will not operate unless the line is clear, in
which case it will provide a message that it allows a dial
tone then dials the number. Before sending the next digit it
will check for a response, this takes into account the
different lengths of phone numbers. The dialler will
provide a message that the phone is ‘ringing’, ‘engaged’ or
‘answered’.
Write an algorithm to describe the operation of the
telephone dialler.

54
Methods of Algorithm Description

Solution This solution used sequence, repeat-until, if-then, while, case


and subprogram structures.

Pseudocode
An algorithm to describe the control of a telephone dialler.
BEGIN MAINPROGRAM
REPEAT
try for phone line
UNTIL the response is a dial tone
send a message to the computer that a clear telephone line is available
REPEAT
REPEAT
get a character from the computer
UNTIL the character is a digit
IF the character is a 0 THEN
set the digit value of the character to 10
ENDIF
assign the digit value of the character to a counter
WHILE counter is greater than 0
send a pulse
decrement the counter
ENDWHILE
send no pulse for two seconds
UNTIL there is a response
determine outcome and send message (response)
END MAINPROGRAM

BEGIN SUBPROGRAM determine outcome and send


message (response)
INITIALISATION
set maxtime to 60
END INITIALISATION
IF response is an engaged tone THEN
send a message that the phone is engaged
ELSE
IF response indicates the phone is ringing THEN
send a message that the phone is ringing
set a timer to 0
REPEAT
check to see if the phone has been answered
increment the timer
UNTIL the phone is answered OR timer is greater than maxtime
CASEWHERE the phone was
answered : send a message that a connection has
been established
unanswered : send a message that no connection has
been established
OTHERWISE : send an error message
ENDCASE
ELSE
send an error message
ENDIF
ENDIF
END SUBPROGRAM determine outcome and send message

55
Methods of Algorithm Description

Flowchart
An algorithm to describe the control of a telephone dialler.

begin

try for a
telephone line

the
False response
is a
dialtone

True
send a message to
the computer that a
clear line is available

get a character
from the computer

False character
is a digit

True

False character True


is a 0
set the value of
character to 10

set a counter to the


value of the character

counter is False
bigger
than 0

True
send a pulse

decrease the
counter by 1

send no pulse
for two seconds

False there is a
response on
the line

True
determine outcome
and send message
(response)

end

56
Methods of Algorithm Description

Subprogram

begin determine
outcome and send
message (response)

set maxtime to 60

True Response False


is engaged
tone
send a message
that the phone
is engaged
False phone is True
ringing

send a message
send an error that the phone
message is ringing

set a timer
to 0

check to see
if the phone
is answered

increment timer

phone is
False answered or
timer > maxtime

True

phone
was

answered unanswered otherwise

send a message send a message send an error


that connection that no connection message
established established

end determine
outcome and
send message

57
Auto Teller Problem
Problem An automatic teller machine has a console as shown in the
diagram below. The teller machine follows this sequence
to assist a customer:
1. The customer will insert their card and enter a PIN. A
customer is allowed at most three tries at their PIN. If
they get it wrong three times the whole process ends
without ejecting the card.
2. If the PIN is correct they will then select an action
button (withdraw, deposit or balance).
3. Next they will select the account type (savings or
cheque).
4. Finally, they will enter the amount in whole dollars (if
appropriate), and press OK to confirm it, and the
transaction will be processed.
The auto teller will eject the customer’s card and stop the
process if the customer presses the ‘Cancel’ button.
Describe an algorithm which the auto teller could use to
accept the details from the customer and act on them.

Auto Teller Console

1 2 3 4 Withdrawal Savings

5 6 7 8 Deposit Cheque

9 0 Balance OK Cancel

58
Methods of Algorithm Description

Solution This solution uses sequence, if-then, repeat-until, while, case


and subprogram structures.

Pseudocode
An algorithm to describe the control of an automatic teller
machine. Input comes from the buttons on the console,
output through a small video screen.

BEGIN MAINPROGRAM
INITIALISATION
set Action to an empty string
set Account to an empty string
set Amount to 0
END INITIALISATION
wait for the card to be inserted
get the PIN and check it (Action)
IF action is ‘cancel’ THEN
eject card
ELSE
IF action is not ‘keep card’ THEN
get action required (Action)
IF action is not ‘cancel’ THEN
get account to be used (Action, Account)
do the transaction
ENDIF
eject card
ENDIF
ENDIF
END MAINPROGRAM

BEGIN SUBPROGRAM wait for the card to be inserted


WHILE no card has been inserted
wait
ENDWHILE
END SUBPROGRAM wait for the card to be inserted

59
Methods of Algorithm Description

BEGIN SUBPROGRAM get the PIN and check it (Action)


INITIALISATION
set OK to FALSE
set NumberOfTries to 3
END INITIALISATION
IF cancel button has been pressed THEN
set Action to ‘cancel’
ELSE
REPEAT
accept a four digit number
decrement NumberOfTries
IF correct PIN THEN
set OK to TRUE
ENDIF
UNTIL OK OR number of tries is 0
IF NOT OK THEN
set Action to ‘keep card’
ENDIF
ENDIF
END SUBPROGRAM get the PIN and check it

BEGIN SUBPROGRAM get action required (Action)


IF cancel button has been pressed THEN
set Action to ‘cancel’
ELSE
REPEAT
prompt user for action key
get a key press
UNTIL key press is an action key
CASEWHERE keypress is
Withdrawal : set Action to ‘withdraw’
Deposit : set Action to ‘deposit’
Balance : set Action to ‘show balance’
Cancel : set Action to ‘cancel’
ENDCASE
ENDIF
END SUBPROGRAM get action required

60
Methods of Algorithm Description

BEGIN SUBPROGRAM get account to be used (Action, Account)


IF cancel button is pressed THEN
set Action to ‘cancel’
ELSE
REPEAT
prompt for account type key
get a keypress
UNTIL keypress is acceptable
CASEWHERE keypress is
savings account : set Account to ‘savings account’
cheque account : set Account to ‘cheque account’
cancel : set Action to ‘cancel’
ENDCASE
ENDIF
END SUBPROGRAM get account to be used

BEGIN SUBPROGRAM get the amount in dollars (Action, Amount)


INITIALISATION
set OK to FALSE
END INITIALISATION
IF the cancel button has been pressed THEN
set Action to ‘cancel’
ELSE
REPEAT
REPEAT
prompt for a keypress
get a keypress
UNTIL keypress is acceptable
CASEWHERE keypress is
OK : set OK to TRUE
cancel : set Action to ‘cancel’
set OK to TRUE
number : set Amount to 10 times the amount
plus digit value of number
ENDCASE
UNTIL OK
ENDIF
END SUBPROGRAM get the amount in dollars

61
Methods of Algorithm Description

BEGIN SUBPROGRAM do the transaction (Action, Account)


IF the cancel button has been pressed THEN
set Action to ‘cancel’
ENDIF
CASEWHERE Action is
cancel: set Amount to 0
set Account to empty string
deposit: get the amount in dollars (Action, Amount)
IF Action is not ‘cancel’ THEN
IF Account is ‘cheque’ THEN
add Amount to cheque account
ELSE
add Amount to savings account
ENDIF
ENDIF
withdraw: get the amount in dollars (Action, Amount)
IF Action is not ‘cancel’ THEN
IF Account is ‘cheque’ THEN
subtract Amount from cheque account
ELSE
subtract Amount from savings account
ENDIF
ENDIF
balance: IF Account is ‘cheque’ THEN
display balance of cheque account
ELSE
display balance of savings account
ENDIF
ENDCASE
END SUBPROGRAM do the transaction

62
Methods of Algorithm Description

Flowchart
An algorithm to describe the control of an automatic teller
machine. Input comes from the buttons on the console,
output through a small video screen.

begin

set Action to
an empty string

set Account to
an empty string

set Amount to 0

wait for card


to be inserted

get the PIN


and check it

False Action is
‘cancel’

Action True
False is not
‘keep card’

True

get Action
required (Action)

False Action is
not
‘cancel’
eject card
True

get Account to
be used
(Action, Account)

do the transaction
(Action, Account)

eject card

end

63
Methods of Algorithm Description

Subprograms

begin wait for card


to be inserted

card not False


inserted

True

wait

end wait for card


to be inserted

64
Methods of Algorithm Description

begin get the PIN


& check it (Action)

set OK to false

set number
of tries to 3

False cancel True


button is
pressed

accept a four set Action


digit number to ‘cancel’

decrement
number of tries

False True
correct PIN

set OK to true

OK = true
False or
number of
tries = 0

True

False True
OK

set Action to
‘keep card’

end get the PIN


and check it

65
Methods of Algorithm Description

begin get action


required (Action)

False cancel True


button is
pressed

prompt for set Action


action key to ‘cancel’

get a keypress

False keypress is
action key

True

keypress is

Withdrawal Deposit Balance Cancel

set Action to set Action to set Action to set Action to


‘withdrawal’ ‘deposit’ ‘show balance’ ‘cancel’

end get Action


required

66
Methods of Algorithm Description

begin get account


to be used
(Action, Account)

False cancel True


button is
pressed

prompt for set Action


account type key to ‘cancel’

get a keypress

False keypress is
acceptable

True

keypress is

cheque account savings account cancel

set Account to set Account to set Action to


‘cheque account’ ‘savings account’ ‘cancel’

end get account


to be used

67
Methods of Algorithm Description

begin get amount


in dollars
(Action, Amount)

set OK to false

False cancel True


button is
pressed

prompt for set Action


a keypress to ‘cancel’

get a keypress

False keypress is
acceptable

True

keypress is

OK cancel number

set Amount to 10
set Action times the amount
set OK to true to ‘cancel’ plus digit value
of number

set OK to true

False
OK is true

True

end get amount


in dollars

68
Methods of Algorithm Description

begin do
transaction
(Action, Account)

False cancel True


button
pressed

set Action
to ‘cancel’
Action is

cancel deposit withdrawal balance

set Amount get Amount in get Amount in


to 0 dollars (Action, dollars (Action,
Amount) Amount) False Account is True
‘cheque’
set Account
to empty
string Action Action
False False display balance display balance
is not is not
‘cancel’ ‘cancel’ of savings of cheque
account account

True True

False Account is True False Account is True


‘cheque’ ‘cheque’

add Amount to add Amount to subtract Amount subtract Amount


savings account cheque account from savings from cheque
account account

end
do transaction

69

You might also like