Q:

C++ program for Banking Management System using Class

belongs to collection: C++ Classes and Object programs

0

C++ program for Banking Management System using Class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C++ program for banking management system

#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;
}

Output

 
Enter Account Number: 111 
Enter Name: Shivang 
EnterBalance: 30000 
Enter Account Number: 112 
Enter Name: Radib 
EnterBalance: 20000 
Enter Account Number: 123 
Enter Name: Prem
EnterBalance: 10000 


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 1 
Account Number: 111 
Name: Shivang 
Balance: 30000
Account Number: 112 
Name: Radib 
Balance: 20000
Account Number: 123 
Name: Prem
Balance: 10000


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 2 
Account Number? 111 
Account Number: 111 
Name: Shivang 
Balance: 30000


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 3 
Account Number To Deposit Amount? 112 
Account Number: 112 
Name: Radib 
Balance: 20000
Enter Amount U want to deposit? 20000 


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 2 
Account Number? 112 
Account Number: 112 
Name: Radib 
Balance: 40000


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 4 
Account Number To Withdraw Amount? 111
Account Number: 111 
Name: Shivang 
Balance: 30000
Enter Amount U want to withdraw? 15000


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 1 
Account Number: 111 
Name: Shivang 
Balance: 15000
Account Number: 112 
Name: Radib 
Balance: 40000
Account Number: 123 
Name: Prem
Balance: 10000


1:Display All 
2:By Account No 
3:Deposit 
4:Withdraw
5:Exit
Please input your choice: 5 
Have a nice day 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Classes and Object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< C++ program Input list of candidates and find winn...