Repository navigation
Expand file tree
/
Copy pathaccount.cpp
More file actions
161 lines (137 loc) · 3.55 KB
/
Copy pathaccount.cpp
File metadata and controls
161 lines (137 loc) · 3.55 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
#include "account.hpp"
unsigned int Account::count = 0;
Account::Account(Name& name, Date& dob, int& pinNumber){
Account::count++;
accNumber = Account::count;
balance = 0;
this->name = name;
this->dob = dob;
this->pinNumber = pinNumber;
}
void Account::deposit(double& amount){
balance += amount;
std::cout << "$" << amount << " Successfully deposited.\n";
}
void Account::withdraw(double& amount){
if((balance - amount) < 0){
std::cout << "Cannot withdraw $" << amount << " because of insufficient funds.\n";
}else{
balance -= amount;
std::cout << "$" << amount << " Successfully withdrawn.\n";
}
}
unsigned int Account::getAccNum(){
return accNumber;
}
double Account::getBalance(){
return balance;
}
std::ostream& operator<<(std::ostream& os, Date& d){
if(d.month < 10){
os << "0" << d.month;
}else{
os << d.month;
}
if(d.day < 10){
os << "/0" << d.day;
}else{
os << "/" << d.day;
}
os << "/" << d.year;
return os;
}
std::istream& operator>>(std::istream& is, Date& d) throw (MenuException){
if(is >> d.month && (d.month < 13) && (d.month > 0)){
//continue;
}else{
throw MenuException("Invalid Month Entered!");
}
if( is >> d.day && (d.day < 31) && (d.day > 0)){
//continue;
}else{
throw MenuException("Invalid Day Entered!");
}
if( is >> d.year && (d.year < 2020) && (d.year > 1900)){
//continue;
}else{
throw MenuException("Invalid Year Entered!");
}
return is;
}
Name Account::getName(){
return name;
}
Date Account::getDOB(){
return dob;
}
int Account::getCount(){
return Account::count;
}
bool operator!=(Date& d1, Date& d2){
bool notSameDate;
if(d1.day != d2.day || d1.year != d2.year || d1.month != d2.month)
notSameDate = true;
else
notSameDate = false;
return notSameDate;
}
std::ostream& operator<<(std::ostream& os, Account& a){
os << "Acct#: " << a.accNumber << " \tName: " << a.name << " \tDOB: " << a.dob;
return os;
}
std::ostream& operator<<(std::ostream& os, Name& n){
os << n.firstName << " " << n.lastName;
return os;
}
std::istream& operator>>(std::istream& is, Name& n){
is >> n.firstName >> n.lastName;
return is;
}
bool operator!=(Name& n1, Name& n2){
if((n1.firstName != n2.firstName) || (n1.lastName != n2.lastName)){
return true;
}else{
return false;
}
}
int Account::getPin(){
return pinNumber;
}
std::ofstream& operator<<(std::ofstream& ofs, Date& d){
ofs << d.month << " " << d.day << " " << d.year;
return ofs;
}
std::ifstream& operator>>(std::ifstream& ifs, Date& d){
ifs >> d.month >> d.day >> d.year;
return ifs;
}
std::ofstream& operator<<(std::ofstream& ofs, Name& n){
ofs << n.firstName << " " << n.lastName;
return ofs;
}
std::ifstream& operator>>(std::ifstream& ifs, Name& n){
ifs >> n.firstName >> n.lastName;
return ifs;
}
std::ofstream& operator<<(std::ofstream& ofs, Account& a){
ofs << a.name << " ";
ofs << a.dob << " ";
if(a.pinNumber < 10){
ofs << "000" << a.pinNumber;
}else if(a.pinNumber < 100){
ofs << "00" << a.pinNumber;
}else if(a.pinNumber < 1000){
ofs << "0" << a.pinNumber;
}else{
ofs << a.pinNumber;
}
ofs << " " << a.balance;
return ofs;
}
std::ifstream& operator>>(std::ifstream& ifs, Account& a){
ifs >> a.name;
ifs >> a.dob;
ifs >> a.pinNumber;
ifs >> a.balance;
return ifs;
}