-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_system.cpp
210 lines (189 loc) · 6.26 KB
/
bank_system.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <iostream>
#include <cmath>
using namespace std;
class Account {
public:
string customer_name;
int account_number;
string account_type;
double balance;
// create account
void create_account(string customer_name, int account_number, string account_type, double balance) {
this->customer_name = customer_name;
this->account_number = account_number;
this->account_type = account_type;
this->balance = balance;
}
// show balance
void showBalance() {
cout << "Your Balance is " << balance << endl;
}
// show account details
void showDetails() {
cout << "Customer Name: " << customer_name
<< "\nAccount Number: " << account_number
<< "\nAccount Type: " << account_type
<< "\nBalance: " << balance << endl;
}
// deposit money
void deposit(double amount) {
if (amount > 0) {
balance += amount;
cout << amount << " is credited successfully.\n";
} else {
cout << "Amount must be greater than 0.\n";
}
}
};
class CurAcct : virtual public Account {
public:
// withdraw money
void withdraw(double amount) {
if (amount <= balance) {
balance -= amount;
cout << "Withdrawn: " << amount << endl;
} else {
cout << "Insufficient balance for withdrawal!" << endl;
}
}
};
class SavAcct : virtual public Account {
private:
double interest_rate;
public:
// set interest rate
void setInterestRate(double rate) {
interest_rate = rate;
}
// interest calculation
void interestAmount(int years) {
double interest = balance * pow(1 + interest_rate / 100, years) - balance;
balance += interest;
cout << "Interest Added: " << interest << endl;
}
//withdraw money
void withdraw(double amount) {
if (amount <= balance) {
balance -= amount;
cout << "Withdrawn: " << amount << endl;
} else {
cout << "Not enough balance for withdrawal" << endl;
}
}
};
int main() {
SavAcct S1;
CurAcct C1;
int choice;
string customer_name;
int account_number;
string account_type;
double balance;
double amount;
double interest_rate;
int years;
while (true) {
cout << "\nOPTIONS - \n";
cout << "1. Create Savings Account\n";
cout << "2. Create Current Account\n";
cout << "3. Deposit\n";
cout << "4. Withdraw\n";
cout << "5. Check Balance\n";
cout << "6. Show Account Details\n";
cout << "7. Add Interest (Savings Account)\n";
cout << "8. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter customer name: ";
cin >> customer_name;
cout << "Enter account number: ";
cin >> account_number;
cout << "Enter initial balance: ";
cin >> balance;
S1.create_account(customer_name, account_number, "Savings", balance);
cout << "Enter interest rate (in %): ";
cin >> interest_rate;
S1.setInterestRate(interest_rate);
cout << "Savings account created \n";
break;
case 2:
cout << "Enter customer name: ";
cin >> customer_name;
cout << "Enter account number: ";
cin >> account_number;
cout << "Enter initial balance: ";
cin >> balance;
C1.create_account(customer_name, account_number, "Current", balance);
cout << "Current account created\n";
break;
case 3:
cout << "Enter account number: ";
cin >> account_number;
cout << "Enter amount to deposit: ";
cin >> amount;
if (S1.account_number == account_number) {
S1.deposit(amount);
} else if (C1.account_number == account_number) {
C1.deposit(amount);
} else {
cout << "Account not found!\n";
}
break;
case 4:
cout << "Enter account number: ";
cin >> account_number;
cout << "Enter amount to withdraw: ";
cin >> amount;
if (S1.account_number == account_number) {
S1.withdraw(amount);
} else if (C1.account_number == account_number) {
C1.withdraw(amount);
} else {
cout << "no account exist \n";
}
break;
case 5:
cout << "Enter account number: ";
cin >> account_number;
if (S1.account_number == account_number) {
S1.showBalance();
} else if (C1.account_number == account_number) {
C1.showBalance();
} else {
cout << "no account\n";
}
break;
case 6:
cout << "Enter account number: ";
cin >> account_number;
if (S1.account_number == account_number) {
S1.showDetails();
} else if (C1.account_number == account_number) {
C1.showDetails();
} else {
cout << "Account not found!\n";
}
break;
case 7:
cout << "Enter account number: ";
cin >> account_number;
if (S1.account_number == account_number) {
cout << "Enter number of years: ";
cin >> years;
S1.interestAmount(years);
} else {
cout << "This option is available only for savings accounts\n";
}
break;
case 8:
cout << "Exit\n";
return 0;
default:
cout << "Invalid choice\n";
break;
}
}
return 0;
}