Problem solving for programming TMA
Instructions: Task 1-6 has to be done
Solution.
Problem solving for programming TMA
TASK 1
PROCEDURE EnterCard
VARIABLES
CARDVALIDITY is BOOLEAN
BEGIN
read card
is card valid
IF cardvalidity is TRUE
THEN go to the next step of the main screens
ELSE Eject Card
ENDIF
END EnterCard
TASK2
PROCEDURE Main
BEGIN
LOOP
IF control system is disabled
THEN BEGIN
display ‘out of service’ message
LOOP UNTIL control system is enabled
END
ELSE IF no card is inserted
THEN display ‘insert card’ message
ELSE CALL PROCEDURE CheckPIN
ENDIF
ENDIF
ENDLOOP
END Main
TASK3
PROCEDURE CheckPIN
BEGIN
LOOP
read data from card
input PIN from customer keypad
IF entered PIN matches card PIN
ELSE CALL PROCEDURE Services
ENDIF
END CheckPIN
TASK4
PROCEDURE Services
VARIABLES
ExitServicesFlag IS BOOLEAN
BEGIN
RESET ExitServicesFlag
LOOP UNTIL ExitServicesFlag is SET
display customer services
input selection from keypad
CASE OF selection:
WHEN display balance
get and display balance
WHEN display withdraw
get and display $10,$20,$50,$100,$200
ENDCASE
ENDLOOP
END Services
TASK 5
PROCEDURE Withdrawal (WithdrawalType)
VARIABLES
Amount IS NUMBER
BEGIN
input Amount from customer keypad
read customer's details from accounts database
IF customer has insufficient funds
THEN IF customer has zero funds
THEN BEGIN
display 'insufficient funds' message
set Amount to zero
END
ELSE BEGIN
display offer of available funds
input customer's response (Y/N)
IF response is 'Y'
THEN set reduced Amount
ELSE set Amount to zero
ENDIF
END
ENDIF
ENDIF
return customer's card
IF Amount is not zero
THEN BEGIN
dispense cash Amount
IF WithdrawalType is with_receipt
THEN print receipt for Amount
ENDIF
update accounts database
END
ENDIF
END Withdrawal
TASK 6
PROCEDURE CheckPIN
CONSTANTS
MAXPINS IS 3
VARIABLES
PINCounter IS NUMBER
BEGIN
read data from card
set PINCounter to zero
LOOP UNTIL PINCounter is equal to MAXPINS
input PIN from customer keypad
IF entered PIN matches card PIN
THEN EXITLOOP
ENDIF
add 1 to PINCounter
ENDLOOP
IF PINCounter is equal to MAXPINS
THEN confiscate customer’s card
ELSE CALL PROCEDURE Services
ENDIF
END CheckPIN