-
Notifications
You must be signed in to change notification settings - Fork 0
/
acctABC.cpp
114 lines (102 loc) · 2.54 KB
/
acctABC.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
// acctabc.cpp -- bank account class methods
#include <iostream>
#include <cstring>
using std::cout;
using std::ios_base;
using std::endl;
#include "acctabc.h"
// Abstract Base Class
AcctABC::AcctABC (const char *s, long an, double bal)
{
std::strncpy(fullName, s, MAX - 1);
fullName[MAX - 1] = '\0';
acctNum = an;
balance = bal;
}
void AcctABC::Deposit (double amt)
{
if (amt < 0) {
cout << "Negative deposit not allowed: "
<< "deposit is cancelled.\n";
} else {
balance += amt;
}
}
void AcctABC::Withdraw (double amt)
{
balance -= amt;
}
// protected methods
ios_base ::fmtflags AcctABC::SetFormat()const
{
ios_base ::fmtflags initialState =
cout.setf(ios_base ::fixed, ios_base ::floatfield);
cout.setf (ios_base ::showpoint);
cout.precision (2);
return initialState;
}
// Brass methods
void Brass ::Withdraw (double amt)
{
if (amt < 0) {
cout << "Withdrawal amount must be postive;"
<< "withdrawal canceled.\n";
} else if (amt <= Balance()) {
AcctABC ::Withdraw (amt);
} else {
cout << "Withdrawal amount of $" << amt
<< " exceeds your balance.\n"
<< "Withdrawal canceled.\n";
}
}
void Brass ::ViewAcct()const
{
ios_base ::fmtflags initialState = SetFormat();
cout << "Brass Client: " << FullName() << endl;
cout << "Account Number: " << AcctNum() << endl;
cout << "Balance: $" << Balance() << endl;
cout.setf (initialState);
}
// BrassPlus methods
BrassPlus ::BrassPlus (const char *s, long an, double bal,
double ml, double r): AcctABC(s, an, bal)
{
maxLoan = ml;
owesBank = 0.0;
rate = r;
}
BrassPlus ::BrassPlus (const Brass & ba, double ml, double r)
: AcctABC (ba) // uses implicit copy construction
{
maxLoan = ml;
owesBank = 0.0;
rate = r;
}
void BrassPlus::ViewAcct()const
{
ios_base ::fmtflags initialState = SetFormat();
cout << "BrassPlus Client: " << FullName() << endl;
cout << "Account Number: " << AcctNum() << endl;
cout << "Balance: $" << maxLoan << endl;
cout << "Owed to bank: $" << owesBank << endl;
cout << "Loan Rate: " << 100 * rate << endl;
cout.setf (initialState);
}
void BrassPlus::Withdraw (double amt)
{
ios_base ::fmtflags initialState = SetFormat();
double bal = Balance();
if (amt <= bal) {
AcctABC ::Withdraw(amt);
} else if (amt <= bal + maxLoan - owesBank) {
double advance = amt - bal;
owesBank += advance * (1.0 + rate);
cout << "Bank advance: $" << advance << endl;
cout << "Fiance charge: $" << advance * rate <<endl;
Deposit(advance);
AcctABC ::Withdraw(amt);
} else {
cout << "Credit limit exceeded. Transaction cancelled.\n";
}
cout.setf (initialState);
}