-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.h
More file actions
225 lines (200 loc) · 5.95 KB
/
Header.h
File metadata and controls
225 lines (200 loc) · 5.95 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
// CIT237-C1
// Project 3
// Checking Account Register Application
// Ximing He
// Aug. 5, 2015
//
///////////////////////////
// Specification file for CheckingInfo class
#ifndef CheckingInfo_H
#define CheckingInfo_H
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include <memory>
#include <cctype>
#include <cstring>
#include <new>
#include <algorithm>
#include <list>
using namespace std;
// CheckingInfo class declaration
class CheckingInfo
{
private:
double currentBalance;
double startingBalance;
int checkNumber;
int transactionType; // 1 = check, 2 = ATM withdrawal, 3 = deposit
string transactionDate;
string transactionDescription;
double paymentAmount;
double depositAmount;
public:
CheckingInfo()
{
// initialize everything first
currentBalance = 0.0;
startingBalance = -1;
checkNumber = 0;
transactionType = 0; // 1 = check, 2 = ATM withdrawal, 3 = deposit, 0 = start
transactionDate = "00/00/0000";
transactionDescription = "";
paymentAmount = 0.0;
depositAmount = 0.0;
}
double getCurrentBalance()
{
return currentBalance;
}
int getCheckNumber()
{
return checkNumber;
}
int getTransactionType()
{
return transactionType;
}
string getTransactionDate()
{
return transactionDate;
}
string getTransactionDescription()
{
return transactionDescription;
}
double getPaymentAmount()
{
return paymentAmount;
}
double getDepositAmount()
{
return depositAmount;
}
void setTransactionType(int input)
{
if (input == 1 || input == 2 || input == 3 || input == 0)
transactionType = input;
else
{
cout << "Something weird happened. Please check the code!!" << endl;
system("pause");
exit(EXIT_FAILURE);
}
} // end setTransactionType(int input)
void setStartingBalance()
{
if (startingBalance != -1)
{
cout << "Starting Balance was set before." << endl;
cout << "Do you want to erase all data and initialize everything ? (Y/N) ";
char temp;
cin.ignore(20, '\n'); // clear the new line charactor in the keyboard buff
cin.get(temp);
while (!(toupper(temp) == 'Y' || toupper(temp) == 'N'))
{
cout << "You have to choose Y or N here. No tricky play." << endl;
cout << "Again? (Y/N) ";
if (temp != '\n')
cin.ignore(20, '\n'); // clear the new line charactor in the keyboard buff
cin.get(temp);
}
cin.ignore(20, '\n'); // clear the new line charactor in the keyboard buff
if (toupper(temp) == 'N')
{
return;
}
else if (toupper(temp) == 'Y')
CheckingInfo();
else
{
cout << "Something weird happened. Please check the code!!" << endl;
system("pause");
exit(EXIT_FAILURE);
}
} // (end if)
cout << endl << "Enter starting balance (with decimal point): ";
cin >> startingBalance;
while (cin.fail() || startingBalance < 0) // no extraction took place
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, '\n'); // clear out the bad input from the stream
cout << "invalid input!! Please enter again." << endl;
cout << "Enter starting balance (with decimal point): ";
cin >> startingBalance;
} // (end while)
currentBalance = startingBalance; // obviously, current balance equals to starting balance
setTransactionDate();
setTransactionDescription();
setTransactionType(0);
} // end setStartingBalance()
void setTransactionDate()
{
cin.ignore(20, '\n'); // clear the new line charactor in the keyboard buff
cout << "Enter transaction date: ";
getline(cin, transactionDate);
if (transactionDate == "")
{
transactionDate = "Today's Date";
}
} // end setTransactionDate()
void setTransactionDescription()
{
// cin.ignore(20, '\n'); // clear the new line charactor in the keyboard buff
cout << "Enter transaction description: " << endl;
getline(cin, transactionDescription);
} // end setTransactionDescription()
void setCheckNumber()
{
cout << "Enter the next check number: ";
cin >> checkNumber;
while (cin.fail() || checkNumber < 0) // no extraction took place
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, '\n'); // clear out the bad input from the stream
cout << "invalid input!! Please enter again." << endl;
cout << "Enter the next check number: ";
cin >> checkNumber;
} // (end while)
cin.ignore(1000, '\n'); // clear out the bad input from the stream
} // end setCheckNumber()
void setCheckNumber(int input)
{
checkNumber = input;
} // end setCheckNumber(int input)
void setPaymentAmount()
{
cout << "Enter the payment amount: ";
cin >> paymentAmount;
while (cin.fail() || paymentAmount <= 0) // no extraction took place
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, '\n'); // clear out the bad input from the stream
cout << "invalid input!! Please enter again." << endl;
cout << "Enter the payment amount: ";
cin >> paymentAmount;
} // (end while)
cin.ignore(1000, '\n'); // clear out the bad input from the stream
currentBalance -= paymentAmount; // update balance
} // end setPaymentAmount()
void setDepositAmount()
{
cout << "Enter the deposit amount: ";
cin >> depositAmount;
while (cin.fail() || depositAmount <= 0) // no extraction took place
{
cin.clear(); // reset the state bits back to goodbit so we can use ignore()
cin.ignore(1000, '\n'); // clear out the bad input from the stream
cout << "invalid input!! Please enter again." << endl;
cout << "Enter the deposit amount: ";
cin >> depositAmount;
} // (end while)
cin.ignore(1000, '\n'); // clear out the bad input from the stream
currentBalance += depositAmount; // update balance
} // end setDepositAmount()
};
#endif