-
Notifications
You must be signed in to change notification settings - Fork 50
/
basicBank.cpp
102 lines (101 loc) · 2.28 KB
/
basicBank.cpp
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
//A program to simulate a simple banking system in which the initial balance and rate of interest are read from the keyword and these values
//are initialised using the constructor member function. The program consists of the following methods:
//->To initialise the balance amount and the rate of interest using the constructor member function
//->To make a deposit
//->To withdraw an amount from the balance
//->To find the compound interest based on the rate of interest
//->To know the balance amount
//->To display the menu options
#include<iostream>
using namespace std;
class account
{
private:
float balance;
float rate;
public:
account();
void deposit();
void withdraw();
void compound();
void getbalance();
void menu();
};
account :: account()
{
cout<<"Enter the initial balance:"<<endl;
cin>>balance;
cout<<"Interest rate in decimal"<<endl;
cin>>rate;
}
void account :: deposit()
{
float amount;
cout<<"enter the amount:"<<endl;
cin>>amount;
balance=balance+amount;
}
void account :: withdraw()
{
float amount;
cout<<"How much to withdraw?"<<endl;
cin>>amount;
if(amount<=balance)
{
balance=balance-amount;
cout<<"Amount drawn="<<amount<<endl;
cout<<"Current balance="<<balance<<endl;
}
else
cout<<0;
}
void account :: compound()
{
float interest;
interest=balance*rate;
balance=balance+interest;
cout<<"Interest amount="<<interest<<endl;
cout<<"Total amount="<<balance<<endl;
}
void account :: getbalance()
{
cout<<"Current balance=";
cout<<balance<<endl;
}
void account :: menu()
{
cout<<"d->deposit"<<endl;
cout<<"w->withdraw"<<endl;
cout<<"c->compound interest"<<endl;
cout<<"q->quit"<<endl;
cout<<"m->menu"<<endl;
cout<<"option, please?"<<endl;
}
int main()
{
class account acct;
char ch;
acct.menu();
while((ch=cin.get())!='q')
{
switch(ch)
{
case 'd':
acct.deposit();
break;
case 'w':
acct.withdraw();
break;
case 'c':
acct.compound();
break;
case 'g':
acct.getbalance();
break;
case 'm':
acct.menu();
break;
}
}
return 0;
}