Bank Account with CPP

-- Leave a Comment
Define a class to represent a bank account. Include the following members:
  1. Data Members:
    1. Name of the account holder
    2. Account number
    3. Balance Amount in account
  2. Member Function:
    1. Open an account
    2. Deposit and Withdraw Fund
    3. Display account information
Write a program to test this class for 10 customers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
110
#include<iostream>
#include<stdio.h>
using namespace std;
class Bank
{
    char name[30];
    double accountno;
	double balance;
    public:
        Bank():balance(0){};
        void create_account(int a);
        void deposit();
        void withdraw();
        void display();
};
void Bank::create_account(int a)
{
    accountno=a;
    cout<<"* Enter Name:- ";
    cin>>name;
    cout<<"***********Account Successfully Created*******"<<endl;
    cout<<"* You Account no is:- "<<a<<endl;

}
void Bank::deposit()
{
	double add;
	cout<<"* Enter Deposite Value:- ";
    cin>>add;
    balance=add+balance;
    cout<<"***********Balance Successfully Deposited*******"<<endl;
}
void Bank::withdraw()
{
	double add;
	cout<<"* Enter Withdraw Value:- ";
    cin>>add;
    if(add<balance){
        cout<<"***********Balance Successfully Withdraw*******"<<endl;
        balance=balance-add;
    }else
        cout<<"***********Problem on Balance Withdraw (Balance Insufficent)*******"<<endl;
}

void Bank::display()
{
	cout<<"* Name:- "<<name<<endl;
    cout<<"* Account no.:- "<<accountno<<endl;
    cout<<"* Current Balance:- "<<balance<<endl;
}

int main()
{
	Bank A[10];
    int a,account,cnum=0;
    int b;
    cout<<"* * * * * * * * * * * * * * * * * * *"<<endl;
    do{
        cout<<"*\tSelect"<<endl<<"*\t1:- To Create Account"<<endl<<"*\t2:- To Deposite"<<endl<<"*\t3:- To Withdraw"<<endl<<"*\t4:- To View Details"<<endl<<"*\t5:- Exit the Program"<<endl<<"* ";
        cin>>a;
    switch(a){
        case 1:
      	{
      		cnum++;
            A[cnum].create_account(cnum);
            cout<<"* Do you want to Process again? (Enter 1 for Yes)";
            cin>>b;
            break;
     	 }
     	 case 2:
     	 {
            cout<<"* Enter Account no:- ";
            cin>>cnum;
            A[cnum].deposit();
            cout<<"* Do you want to Process again? (Yes=1 / NO=2)";
            cin>>b;
            break;
     	 }
     	 case 3:
      	{
      		cout<<"* Enter Account no:- ";
            cin>>cnum;
            A[cnum].withdraw();
            cout<<"* Do you want to Process again? (Yes=1 / NO=2)";
            cin>>b;
            break;
     	 }
     	 case 4:
      	{
            cout<<"* Enter Account no:- ";
            cin>>cnum;
            A[cnum].display();
            cout<<"* Do you want to Process again? (Yes=1 / NO=2)";
            cin>>b;
            break;
     	 }
     	 case 5:
      	{
      		cout<<"* Thanks For Using this Program";
            b = 2;
            break;
     	 }
     	 default:
     	 {
            cout<<"* Please Enter the Selected Option";
            b = 1;
     	 }
   	}
    }while(b == 1);
   return 0;
}

Here is the Output:-

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment