-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.cpp
236 lines (214 loc) · 5.99 KB
/
Account.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <iostream>
#include <cstring>
#include <cctype>
#include <conio.h>
using namespace std;
const double sav_minbalance = 5000;
const double curr_minbalance = 1000;
const double interestRate = 0.05;
class Account {
protected:
string depositorName;
string accountType;
long accountNumber;
double balance = 0;
public:
// constructor
Account(const string& name, long accNumber, double balance)
{
depositorName = name;
this->accountNumber = accNumber;
this->balance = balance;
}
// accept deposit
void deposit()
{
double amount;
cout << "Enter amount to deposit: " << endl;
cin >> amount;
balance += amount;
cout << "You successfully deposited $ " << amount << endl;
}
// account details
void display()
{
cout << "=================== Account Details =======================" << endl;
cout << "Holder's Name: " << depositorName << endl;
cout << "Account No: " << accountNumber << endl;
cout << "Balance: $ " << balance << endl;
}
// permit withdrawal and update balance
void permitWithdraw()
{
int n;
cout << "Enter 1 to confirm or 2 to cancel." << endl;
cin >> n;
if (n == 1)
{
cout << "Transaction has been successful" << endl << endl;
}
else if (n == 2)
{
cout << "Transaction cancelled." << endl;
}
else
{
cout << "Wrong entry try again." << endl;
}
}
// check minimum balance, impose penalty and update balance
void penalty()
{
if (balance < sav_minbalance)
{
double penalty = balance * 0.1;
balance -= penalty;
cout << "A fine of $ " << penalty << " has been imposed on your account." << endl;
}
else if (balance < curr_minbalance)
{
double penalty = balance * 0.05;
balance -= penalty;
cout << "A fine of $ " << penalty << " has been imposed on your account." << endl;
}
else
{
cout << "You have $ " << balance << " in your account. Thanks" << endl;
}
}
};
class Curr_Account : public Account
{
public:
Curr_Account(const string& name, long accNumber, double balance) : Account(name, accNumber, balance) {}
// withdraw
void withdraw()
{
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
if (((balance - amount) > 0) && (balance > curr_minbalance))
{
balance -= amount;
permitWithdraw();
}
else
{
cout << "Insufficient balance" << endl;
}
}
};
class Sav_Account : public Account
{
public:
Sav_Account(const string& name, long accNumber, double balance) : Account(name, accNumber, balance) {}
// withdraw
void withdraw()
{
double amount;
cout << "Enter amount to withdraw: ";
cin >> amount;
if (((balance - amount) > 0) && (balance > sav_minbalance))
{
balance -= amount;
permitWithdraw();
}
else
{
cout << "Insufficient balance" << endl << endl;
}
}
// interest computation
void compInterest()
{
int t;
double interest;
cout << "Enter the number of years: ";
cin >> t;
interest = balance * interestRate * t;
balance += interest;
cout << "Interest of $ " << interest << " has been added to your account" << endl;
}
};
int main() {
const int maxCustomers = 100;
Account* accounts[maxCustomers];
int numCustomers = 0;
Curr_Account c("John", 253534, 60000.0);
Sav_Account s("Doe", 7357634, 80000.0);
accounts[numCustomers++] = &c;
accounts[numCustomers++] = &s;
do
{
int option1;
cout << "=================== WELCOME TO DFCU BANK ========================" << endl;
cout << endl;
cout << "Select Account Type. " << endl;
cout << "1. Saving Account " << endl;
cout << "2. Current Account " << endl;
cout << endl;
cin >> option1;
switch (option1)
{
case 1:
int options;
cout << "=========== SAVING ACCOUNT ===============" << endl;
cout << "1. Withdraw " << endl;
cout << "2. Compute Interest " << endl;
cout << "3. Check Balance " << endl;
cout << "4. Account Details " << endl;
cout << "5. Exit program";
cout << endl;
cout << "Choose an option? " << endl;
cin >> options;
switch (options)
{
case 1:
s.withdraw();
break;
case 2:
s.compInterest();
break;
case 3:
s.penalty();
break;
case 4:
s.display();
break;
case 5:
return 0;
default:
cout << "Wrong choice. Try again" << endl;
}
break;
case 2:
int optionc;
cout << "================ CURRENT ACCOUNT ================" << endl;
cout << "1. Withdraw " << endl;
cout << "2. Check Balance " << endl;
cout << "3. Account Details " << endl;
cout << "4. Exit Program ";
cout << endl;
cout << "Choose an option? " << endl;
cin >> optionc;
switch (optionc)
{
case 1:
c.withdraw();
break;
case 2:
c.penalty();
break;
case 3:
c.display();
break;
case 4:
return 0;
default:
cout << "Wrong choice. Try again" << endl;
}
break;
}
} while (1);
return 0;
}