The ATM Requirement Documents
In Object-Oriented Programming (OOP), the term “ATM Requirement
Documents” would refer to the documentation that outlines the requirements for
designing an Automated Teller Machine (ATM) system using OOP principles.
These documents would detail the system’s expected functionalities, such as
handling user authentication, processing transactions like cash withdrawals and
deposits, and maintaining account balances. They would also specify the classes,
objects, methods, and properties needed to build the system.
For instance, the requirements might include:
1. A User class with properties like card number and PIN, and methods for
inserting a card and entering a PIN.
2. An ATM class with methods to authenticate users, process transactions, and
manage the session state.
3. A Transaction class to handle different types of transactions, such as
balance inquiries, deposits, and withdrawals.
An ATM is a device that enables bank account holders to perform basic,
self-service financial transactions using their debit cards. As we approach
this problem, we’ll outline the specific requirements for an ATM system:
1. User and Bank Account:
o Each user has one bank account at the bank.
o The user should be able to insert their card and perform transactions.
2. Authentication:
o The ATM should authenticate the user based on the entered PIN (Personal
Identification Number).
3. Transaction Types:
o Once authenticated, the user should be able to perform the following
transactions:
View account balance
Deposit cash
Withdraw cash
o Note that the user can only perform one transaction at a time.
4.Transaction Completion:
o At the end of a transaction, the ATM should display appropriate messages to
communicate the success or failure of the transaction.
o After completing a transaction, the user should be able to start another one.
o The card should be returned to the user when they exit.
5. ATM States:
o To manage the ATM’s behavior, we define different states it can be in at any
given time:
READY: Ready to accept a card.
ENTER PIN: Waiting for the user to enter their PIN after card insertion.
SELECT TRANSACTION: Awaiting the user’s selection of a transaction
type.
DEPOSIT: Waiting for the user to insert cash (after selecting the deposit
option).
WITHDRAW: Awaiting the user to input the required withdrawal amount
(after selecting the withdraw option).
By modeling the ATM system with these requirements and states, we can
design an object-oriented solution that effectively handles user interactions
and transaction processing. Remember, the essence of object-oriented design
lies in representing real-world entities (like the ATM and its users) as
objects with data and behavior.
Program
#include <iostream>
using namespace std;
class Account {
private:
double balance;
public:
Account(double bal) : balance(bal) {}
void Deposit() {
double amount;
cout << "Enter amount to deposit: ";
cin >> amount;
if (amount > 0) {
balance += amount;
cout << "Amount Deposited: " << amount << endl;
} else {
cout << "Invalid amount" << endl;
}
}
void Withdraw() {
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
if (amount > 0 && amount <= balance) {
balance -= amount;
cout << "Amount Withdrawn: " << amount << endl;
} else {
cout << "Insufficient balance or invalid amount" << endl;
}
}
void DisplayBalance() const {
cout << "Current Balance: " << balance << endl;
}
};
int main() {
double initialBalance;
cout << "Enter initial balance: ";
cin >> initialBalance;
Account myAccount(initialBalance);
int action;
do {
cout << "Select action: (1) Deposit, (2) Withdraw, (3) Check Balance,
(0) Exit: ";
cin >> action;
switch (action) {
case 1:
myAccount.Deposit();
break;
case 2:
myAccount.Withdraw();
break;
case 3:
myAccount.DisplayBalance();
break;
case 0:
cout << "Thank you for using the ATM." << endl;
break;
default:
cout << "Invalid selection. Please try again." << endl;
}
} while (action != 0);
return 0;
}
Explanation:
Certainly! The C++ program you provided is a simple simulation of an ATM
system. It allows a user to perform basic banking operations such as depositing and
withdrawing money, as well as checking the account balance. Here’s a breakdown
of the program:
Account Class: This class represents a bank account with a private member
balance to store the account balance. It has three public methods:
i. Deposit(): Prompts the user to enter an amount to deposit. If the amount is
positive, it adds the amount to the balance and displays the deposited
amount.
ii. Withdraw(): Asks the user to enter an amount to withdraw. If the amount is
positive and less than or equal to the balance, it deducts the amount from the
balance and displays the withdrawn amount. Otherwise, it shows an error
message.
iii. DisplayBalance(): Displays the current balance of the account.
iv. Main Function: This is where the program starts execution. It performs the
following steps:
o Asks the user to enter the initial balance and creates an Account object with
that balance.
o Enters a loop that presents the user with a menu to select an action (deposit,
withdraw, check balance, or exit).
o Based on the user’s selection, it calls the appropriate method of the Account
object.
o The loop continues until the user chooses to exit (by entering 0).