$25
Exercise 1.
(100 points) You are developing a banking system to manage both your normal and credit accounts. There are two types of accounts: normal account and credit account. We define the base class of Account, which the NormalAccount and CreditAccount classes could derive it from. The base class offers three main functionalities: “Deposit”, “Withdraw” and displaying account information that correspond to Deposit(), Withdraw(), and ShowAccountInfo() member functions, respectively (Listing 1). The AccountHandler class maintains an array for all accounts with an account identifier as well as providing interfaces with a user (e.g., menu).
We will give you a skeleton to fill out important features for a full-fledged banking system. Write your own code where the comment line starts with the descriptions of // HERE:, which indicates each point you can obtain per successful implementation. Through this homework assignment, you should be able to design and implement a program in an object-oriented manner. Here are considerations for your implementation.
• You may assume all inputs are within expected bounds.
• You may add more member variables or functions if needed.
• You must follow instructions in sources when writing your own code.
• You do not need to modify Makefile.
• You do not need to modify the main() function.
• You can find the sample output useful in Listing 2.
// Account class
class Account
{ private: int accountID; int balance; string customerName;
public:
Account(int ID, int money, string name); int GetAccountID() const; virtual void Deposit(int money); int Withdraw(int money) ;
void ShowAccountInfo() const ;
};
// NormalAccount class class NormalAccount : public Account
{ private:
float interestRate;
public:
NormalAccount(int ID, int money, string name, float
: Account(ID, money, name), interestRate(rate)
{ }
virtual void Deposit(int money)
{ if(money<0) throw NegativeAmountException(money);
Account::Deposit(money);
Account::Deposit(money*(interestRate/100.0)); }
};
// CreditAccount class
class CreditAccount : public NormalAccount
rate)
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
{ private:
float specialRate;
public:
CreditAccount(int ID, int money, string name, int rate, float special) : NormalAccount(ID, money, name, rate), specialRate(special)
{ }
virtual void Deposit(int money)
{
if(money < 0) throw NegativeAmountException(money);
NormalAccount::Deposit(money);
Account::Deposit(money*(specialRate/100.0)); }
};
// AccountHandler class
class AccountHandler
{ private:
BoundCheckArray<Account*> accountArray; int accNum;
public:
AccountHandler(); void ShowMenu(void) const; void OpenAccount(void); void DepositMoney(void); void WithdrawMoney(void);
void ShowAllAccountInfo(void) const;
~AccountHandler();
protected: void OpenNormalAccount(void); void OpenCreditAccount(void);
void OpenCreditAccountHelper(int id, int balance, string name, float interestRate, int credit_level); };
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 Listing 1: Account/BankAccount/CreditAccount/AccountHandler class prototypes for Exercise 1.
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 1
[Select an Account]
1. Normal account 2. Stock account
Enter: 1
[Open Normal Account] Account ID: 100
Account name: Alice
Amount for deposit: 1000 Interest rate: 0.03
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. Terminate
Choice: 2
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
[DEPOSIT]
Account ID: 100 Deposit amount: 2500 Deposite completed!
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 1
[Select an Account]
1. Normal account 2. Stock accountEnter: 2
[Open Credit Account] Account ID: 200
Name: Bob
Amount for deposit: 30000
Credit level (A, B, C): A Interest rate: 0.07
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 4
Account ID : 100
Account Name: Alice
Balance : 3500
Account ID : 200 Account Name: Bob
Balance : 30000
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 3
[WITHDRAW]
Account ID: 200
Withdraw amount: 50000
Insufficient amount: 20000 from your balance!
Enter the amount for withdraw: Withdraw amount: 12000 Withdraw completed!
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 4
Account ID : 100
Account Name: Alice
Balance : 3500
Account ID : 200
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
Account Name: Bob
Balance : 18000
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 2
[DEPOSIT]
Account ID: 100 Deposit amount: -20
Invalid Balance: -20!
Enter the amount for deposit: Deposit amount: 10000 Deposite completed!
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. TerminateChoice: 4
Account ID : 100
Account Name: Alice Balance : 13502
Account ID : 200 Account Name: Bob
Balance : 18000
-----Menu-----1. Open
2. Deposit
3. Withdraw
4. Show
5. Terminate
Choice: 5
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
Listing 2: Sample output for Exercise 1.