-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingSystem.cpp
More file actions
326 lines (257 loc) · 5.34 KB
/
BankingSystem.cpp
File metadata and controls
326 lines (257 loc) · 5.34 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
const int NAME_LEN = 20;
enum { MAKE = 1, DEPOSIT, WITHDRAW, INQUIRE, EXIT };
enum{LEV_A=7, LEV_B=4,LEV_C=2};
enum {NORMAL=1, HIGH=2};
class Account
{
private:
int accID;
int balance;
char *cusName;
public:
Account(const int id, const int money, const char *name);
Account(const Account& copy);
int getAccID() const;
virtual void Deposit(int money);
int Withdraw(int money);
void showAccInfo() const;
~Account();
};
Account::Account(const int id, const int money, const char *name)
:accID(id), balance(money)
{
cusName = new char[strlen(name) + 1];
strcpy(cusName, name);
}
Account::Account(const Account& copy)
:accID(copy.accID), balance(copy.balance)
{
cusName = new char[strlen(copy.cusName) + 1];
strcpy(cusName, copy.cusName);
}
int Account::getAccID() const
{
return accID;
}
void Account::Deposit(int money)
{
balance += money;
}
int Account::Withdraw(int money)
{
if (balance < money)
return 0;
else
{
balance -= money;
return money;
}
}
void Account::showAccInfo() const
{
cout << "계좌번호: " << accID << endl;
cout << "이 름: " << cusName << endl;
cout << "잔 액: " << balance << endl;
cout << endl;
}
Account::~Account()
{
delete[]cusName;
}
class NormalAccount : public Account
{
private:
int interRate;
public:
NormalAccount(const int ID, const int money, const char * name, const int rate)
:Account(ID, money, name), interRate(rate)
{
}
virtual void Deposit(int money)
{
Account::Deposit(money);
Account::Deposit(money*(interRate / 100.0));
}
};
class HighCreditAccount : public NormalAccount
{
private:
int lev;
public:
HighCreditAccount(const int ID, const int money, const char * name, const int rate, const int level)
:NormalAccount(ID, money, name, rate), lev(level)
{
}
virtual void Deposit(int money)
{
NormalAccount::Deposit(money);
Account::Deposit((money)*(lev / 100.0));
}
};
class AccountHandler
{
private:
Account * accArr[100];
int accNum;
public:
AccountHandler();
void ShowMenu(void) const;
void MakeAccount(void);
void DepositMoney(void);
void WithdrawMoney(void);
void ShowAllAccInfo(void);
~AccountHandler();
protected:
void MakeNormalAccount(void);
void MakeCreditAccount(void);
};
AccountHandler::AccountHandler() : accNum(0)
{
}
void AccountHandler::ShowMenu(void) const
{
cout << "----MENU----" << endl;
cout << "1. 계좌개설" << endl;
cout << "2. 입 금" << endl;
cout << "3. 출 금" << endl;
cout << "4. 계좌정보 전체 출력" << endl;
cout << "5. 프로그램 종료" << endl;
}
void AccountHandler::MakeAccount(void)
{
int type;
cout << "[계좌종류선택]" << endl;
cout << "1.보통예금계좌 ";
cout << "2.신용신뢰계좌" << endl;
cout << "선택: "; cin >> type;
if (type == NORMAL)
MakeNormalAccount();
else
MakeCreditAccount();
}
void AccountHandler::MakeNormalAccount(void)
{
int id;
int balance;
int rate;
char name[NAME_LEN];
cout << "[보통계좌개설]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "이 름: "; cin >> name;
cout << "입금액: "; cin >> balance;
cout << "이자율: "; cin >> rate;
cout << endl;
accArr[accNum] = new NormalAccount(id, balance, name, rate);
accNum++;
}
void AccountHandler::MakeCreditAccount(void)
{
int id;
int balance;
int rate;
int lev;
char name[NAME_LEN];
cout << "[신용계좌개설]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "이 름: "; cin >> name;
cout << "입금액: "; cin >> balance;
cout << "이자율: "; cin >> rate;
cout << "신용등급(1toA, 2toB, 3toC): "; cin >> lev;
cout << endl;
switch (lev)
{
case 1:
accArr[accNum++] = new HighCreditAccount(id, balance, name, rate, LEV_A);
break;
case 2:
accArr[accNum++] = new HighCreditAccount(id, balance, name, rate, LEV_B);
break;
case 3:
accArr[accNum++] = new HighCreditAccount(id, balance, name, rate, LEV_C);
break;
}
}
void AccountHandler::DepositMoney(void)
{
int money;
int id;
cout << "[입 금]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "입금액: "; cin >> money;
for (int i = 0; i < accNum; i++)
{
if (accArr[i]->getAccID() == id)
{
accArr[i]->Deposit(money);
cout << "입금완료" << endl;
return;
}
}
cout << "잘못된 id입력" << endl;
}
void AccountHandler::WithdrawMoney(void)
{
int money;
int id;
cout << "[출 금]" << endl;
cout << "계좌ID: "; cin >> id;
cout << "출금액: "; cin >> money;
for (int i = 0; i < accNum; i++)
{
if (accArr[i]->getAccID() == id)
{
if (accArr[i]->Withdraw(money) == 0)
cout << "잔액부족" << endl;
cout << "출금완료" << endl;
return;
}
}
cout << "잘못된 id입력" << endl;
}
void AccountHandler::ShowAllAccInfo(void)
{
for (int i = 0; i < accNum; i++)
{
accArr[i]->showAccInfo();
}
}
AccountHandler::~AccountHandler()
{
for (int i = 0; i < accNum; i++)
delete accArr[i];
}
int main()
{
AccountHandler manager;
int choice;
while (1) {
manager.ShowMenu();
cout << "선택: ";
cin >> choice;
cout << endl;
switch (choice)
{
case MAKE:
manager.MakeAccount();
break;
case DEPOSIT:
manager.DepositMoney();
break;
case WITHDRAW:
manager.WithdrawMoney();
break;
case INQUIRE:
manager.ShowAllAccInfo();
break;
case EXIT:
return 0;
default:
cout << "Illegal selction.." << endl;
}
}
return 0;
}