KEMBAR78
Banking Mgt-Multiple Ac in Java & C++ | PDF | C++ | Computer Engineering
0% found this document useful (0 votes)
2 views6 pages

Banking Mgt-Multiple Ac in Java & C++

The document contains Java and C++ implementations of a banking management system that allows users to manage multiple accounts. Users can open accounts, display account details, deposit and withdraw money, and search for accounts by number. The programs utilize classes and methods to encapsulate account functionalities and provide a menu-driven interface for user interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Banking Mgt-Multiple Ac in Java & C++

The document contains Java and C++ implementations of a banking management system that allows users to manage multiple accounts. Users can open accounts, display account details, deposit and withdraw money, and search for accounts by number. The programs utilize classes and methods to encapsulate account functionalities and provide a menu-driven interface for user interaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Java program for banking management

system- Multiple Accounts Entry


import java.util.Scanner;
class Bank {
private String accno;
private String name;
private long balance;
Scanner KB = new Scanner(System.in);
//method to open an account
void openAccount() {
System.out.print("Enter Account No: ");
accno = KB.next();
System.out.print("Enter Name: ");
name = KB.next();
System.out.print("Enter Balance: ");
balance = KB.nextLong();
}

//method to display account details


void showAccount() {
System.out.println(accno + "," + name + "," + balance);
}
//method to deposit money
void deposit() {
long amt;
System.out.println("Enter Amount U Want to Deposit : ");
amt = KB.nextLong();
balance = balance + amt;
}
//method to withdraw money
void withdrawal() {
long amt;
System.out.println("Enter Amount U Want to withdraw : ");
amt = KB.nextLong();
if (balance >= amt) {
balance = balance - amt;
} else {
System.out.println("Less Balance..Transaction Failed..");
}
}
//method to search an account number
boolean search(String acn) {
if (accno.equals(acn)) {
showAccount();
return (true);
}
return (false);
}
}
public class ExBank {
public static void main(String arg[]) {
Scanner KB = new Scanner(System.in);
//create initial accounts
System.out.print("How Many Customer U Want to Input : ");
int n = KB.nextInt();
Bank C[] = new Bank[n];
for (int i = 0; i < C.length; i++) {
C[i] = new Bank();
C[i].openAccount();
}

//run loop until menu 5 is not pressed


int ch;
do {
System.out.println("Main Menu\n1. Display All\n 2. Search By Account\n 3. Deposit\n 4.
Withdrawal\n 5.Exit ");
System.out.println("Ur Choice :"); ch = KB.nextInt();
switch (ch) {
case 1:
for (int i = 0; i < C.length; i++) {
C[i].showAccount();
}
break;
case 2:
System.out.print("Enter Account No U Want to Search...: ");
String acn = KB.next();
boolean found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(acn);
if (found) {
break;
}
}
if (!found) {
System.out.println("Search Failed..Account Not Exist..");
}
break;
case 3:
System.out.print("Enter Account No : ");
acn = KB.next();
found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(acn);
if (found) {
C[i].deposit();
break;
}
}
if (!found) {
System.out.println("Search Failed..Account Not Exist..");
}
break;
case 4:
System.out.print("Enter Account No : ");
acn = KB.next();
found = false;
for (int i = 0; i < C.length; i++) {
found = C[i].search(acn);
if (found) {
C[i].withdrawal();
break;
}
}
if (!found) {
System.out.println("Search Failed..Account Not Exist..");
}
break;
case 5:
System.out.println("Good Bye..");
break;
}
}
while (ch != 5);
}
}

In C++
#include <iostream>
using namespace std;

// class
class Bank {
private:
int acno;
char name[30];
long balance;

public:
void OpenAccount()
{
cout << "Enter Account Number: ";
cin >> acno;
cout << "Enter Name: ";
cin >> name;
cout << "Enter Balance: ";
cin >> balance;
}
void ShowAccount()
{
cout << "Account Number: " << acno << endl;
cout << "Name: " << name << endl;
cout << "Balance: " << balance << endl;
}
void Deposit()
{
long amt;
cout << "Enter Amount U want to deposit? ";
cin >> amt;
balance = balance + amt;
}
void Withdrawal()
{
long amt;
cout << "Enter Amount U want to withdraw? ";
cin >> amt;
if (amt <= balance)
balance = balance - amt;
else
cout << "Less Balance..." << endl;
}
int Search(int);
};

int Bank::Search(int a)
{
if (acno == a) {
ShowAccount();
return (1);
}
return (0);
}

// main code
int main()
{
Bank C[3];

int found = 0, a, ch, i;


for (i = 0; i <= 2; i++) {
C[i].OpenAccount();
}

do {
// display options
cout << "\n\n1:Display All\n2:By Account No\n3:Deposit\n4:Withdraw\n5:Exit" << endl;

// user input
cout << "Please input your choice: ";
cin >> ch;

switch (ch) {
case 1: // displating account info
for (i = 0; i <= 2; i++) {
C[i].ShowAccount();
}
break;
case 2: // searching the record
cout << "Account Number? ";
cin >> a;
for (i = 0; i <= 2; i++) {
found = C[i].Search(a);
if (found)
break;
}
if (!found)
cout << "Record Not Found" << endl;
break;
case 3: // deposit operation
cout << "Account Number To Deposit Amount? ";
cin >> a;
for (i = 0; i <= 2; i++) {
found = C[i].Search(a);
if (found) {
C[i].Deposit();
break;
}
}
if (!found)
cout << "Record Not Found" << endl;
break;
case 4: // withdraw operation
cout << "Account Number To Withdraw Amount? ";
cin >> a;
for (i = 0; i <= 2; i++) {
found = C[i].Search(a);
if (found) {
C[i].Withdrawal();
break;
}
}
if (!found)
cout << "Record Not Found" << endl;
break;
case 5: // exit
cout << "Have a nice day" << endl;
break;
default:
cout << "Wrong Option" << endl;
}
} while (ch != 5);
return 0;
}

You might also like