A simple banking program needs to perform the following operations on an account balance: Deposit money Withdraw money (checking sufficient funds) Check bal...

Assessment: Computer Science (9-1) 0984 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science (9-1) - 0984

Question 1 Report

A simple banking program needs to perform the following operations on an account balance:

  • Deposit money
  • Withdraw money (checking sufficient funds)
  • Check balance
  • Calculate interest (2% per year)

(a) Write pseudocode for four separate subprograms (one for each operation). Use appropriate choices of procedure or function, with BYREF where needed. [4]

Answer Details

(a) Four separate subprograms for a banking system:

PROCEDURE Deposit(BYREF Balance : REAL, Amount : REAL)
    IF Amount > 0 THEN
        Balance ← Balance + Amount
        OUTPUT "Deposited: ", Amount, ". New balance: ", Balance
    ELSE
        OUTPUT "Invalid amount"
    ENDIF
ENDPROCEDURE

Deposit uses a procedure with BYREF to modify the balance directly. It validates that the amount is positive. [1]

FUNCTION Withdraw(BYREF Balance : REAL, Amount : REAL) RETURNS BOOLEAN
    IF Amount <= 0 THEN
        OUTPUT "Invalid amount"
        RETURN FALSE
    ENDIF
    IF Amount > Balance THEN
        OUTPUT "Insufficient funds. Balance: ", Balance
        RETURN FALSE
    ENDIF
    Balance ← Balance - Amount
    OUTPUT "Withdrawn: ", Amount, ". New balance: ", Balance
    RETURN TRUE
ENDFUNCTION

Withdraw checks both validity and sufficient funds before deducting. It returns a Boolean indicating success. [1]

PROCEDURE CheckBalance(Balance : REAL)
    OUTPUT "Current balance: ", Balance
ENDPROCEDURE

CheckBalance passes Balance by value (read-only) since it only displays the value. [1]

FUNCTION CalculateInterest(Balance : REAL) RETURNS REAL
    RETURN Balance * 0.02
ENDFUNCTION

CalculateInterest is a function because it computes and returns a value (2% of the balance) without modifying the balance itself. [1]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning