C++ Project – ATM Management System
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// ATM Bank Application
#include <iostream>
#include <string.h>
#include <cstdlib> // for system("cls")
#include <conio.h> // for getch()
using namespace std;
class ATM
{
private:
int acno;
string name;
int amount;
public:
void createAccount()
{
cout << "\nEnter Account Number: ";
cin >> acno;
cout << "Enter Your Name: ";
cin >> name;
cout << "Enter Initial Amount: ";
cin >> amount;
}
void deposit()
{
int amt;
cout << "Name: " << name << endl;
cout << "Enter amount to deposit: ";
cin >> amt; //5000
if (amt < 0) {
cout << "Invalid amount.\n";
} else {
amount += amt;
cout << "Deposit successful.\n";
}
}
void withdraw()
{
int amt;
cout << "Name: " << name << endl;
cout << "Enter amount to withdraw: ";
cin >> amt;
if (amt < 0 || amt > amount) {
cout << "Invalid or insufficient amount.\n";
} else {
amount -= amt;
cout << "Withdrawal successful.\n";
}
}
void displayBalance()
{
cout << "\nAccount No: " << acno;
cout << "\nName: " << name;
cout << "\nBalance: " << amount << "\n";
}
void displayDetails() {
cout << "\n" << acno << "\t" << name << "\t" << amount;
}
int getAccountNumber()
{
return acno;
}
};
// Global array for 5 accounts
ATM accounts[5]; // Array of Object
int accountCount = 0;
void design()
{
cout << "\n---- ATM Banking Management System ----\n";
cout << "1. Create Account\n";
cout << "2. Deposit Amount\n";
cout << "3. Withdraw Amount\n";
cout << "4. Check Balance\n";
cout << "5. Display All Accounts\n";
cout << "6. Exit\n";
cout << "---------------------------------------\n";
}
void createAccounts()
{
for (int i = 0; i < 5; i++)
{
cout << "\nCreating Account " << i + 1 << ":\n";
accounts[i].createAccount(); //accounts[1]
}
accountCount = 5;
}
void depositAmount()
{
int acc;
cout << "Enter Account Number: ";
cin >> acc;
for (int i = 0; i < accountCount; i++)
{
if (accounts[i].getAccountNumber() == acc)
{
accounts[i].deposit();
return;
}
}
cout << "Account not found.\n";
}
void withdrawAmount()
{
int acc;
cout << "Enter Account Number: ";
cin >> acc;
for (int i = 0; i < accountCount; i++)
{
if (accounts[i].getAccountNumber() == acc)
{
accounts[i].withdraw();
return;
}
}
cout << "Account not found.\n";
}
void checkBalance()
{
int acc;
cout << "Enter Account Number: ";
cin >> acc;
for (int i = 0; i < accountCount; i++) {
if (accounts[i].getAccountNumber() == acc) {
accounts[i].displayBalance();
return;
}
}
cout << "Account not found.\n";
}
void displayAllAccounts() {
cout << "\nAccount No\tName\tBalance";
for (int i = 0; i < accountCount; i++) {
accounts[i].displayDetails();
}
cout << "\n";
}
int main() {
system("cls"); // Clears screen
char pin[5];
cout << "Enter your 4-character PIN: ";
for (int i = 0; i < 4; i++)
{
pin[i] = getch();
cout << "*";
}
pin[4] = '\0';
if (strcmp(pin, "data") == 0)
{
int choice;
do {
design();
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice)
{
case 1: createAccounts(); break;
case 2: depositAmount(); break;
case 3: withdrawAmount(); break;
case 4: checkBalance(); break;
case 5: displayAllAccounts(); break;
case 6: cout << "Exiting...\n"; break;
default: cout << "Invalid choice.\n"; break;
}
} while (choice != 6);
} else {
cout << "\nInvalid PIN.\n";
}
return 0;
}
Did you like this article? If Yes, please give DataFlair 5 Stars on Google

