-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountClass.h
308 lines (281 loc) · 8.82 KB
/
accountClass.h
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
#include "reusedFunctions.h"
#include <string>
#include <cmath>
#define interestRate 1.5
#define minmumBalanceForInterest 200
/* ========================================================
**********************ACCOUNT_CLASS***********************
========================================================*/
class account
{
private:
string name;
string userName;
int size;
int pin;
double *movements;
double totalBalance;
double income;
double outcome;
double interest;
bool sort;
public:
//CONSTRUCTORS
account(string, string, int, int, double, double, double, double, bool, double *);
account(const account &);
//SETTERS
void setName(string);
void setUserName(string);
void setPin(int);
void setSize(int);
void setTotalBalance(double);
void setIncome(double);
void setOutcome(double);
void setInterest(double);
void setSort(bool);
void setMovementsAddress(double *);
void setMovementsValue();
void setData(string, string, int, int, double *, double, double, double, double, bool);
//GETTERS
string getName();
string getUserName();
int getPin();
int getSize();
double getTotalBalance();
double getIncome();
double getOutcome();
double getInterest();
bool getSort();
double *getMovementsAddress();
void getMovementsValue();
void getData();
//FUNCTIONALITY-FUNCTIONS
void createAccount();
void calculateUserName();
double calculateTotalBalance();
double calculateTotalIncome();
double calculateTotalOutcome();
double calculateTotalInterest();
void sortMovements();
//DESTRUCTOR
~account();
};
/* ==============================================================================================
*******************************CLASS_MEMBER_FUNCTIONS_BODY***************************************
================================================================================================*/
/* ========================================================
************************CONSTRUCTORS**********************
========================================================*/
// OVERLOADED_CONSTRUCTOR(sum of default and parameterized)
account::account(string name = "", string userName = "", int pin = 0, int size = 0, double totalBalance = 0.0, double income = 0.0, double outcome = 0.0, double interest = 0.0, bool sort = false, double *movements = nullptr)
{
setName(name);
setUserName(userName);
setPin(pin);
setSize(size);
setTotalBalance(totalBalance);
setIncome(income);
setOutcome(outcome);
setInterest(interest);
setSort(sort);
setMovementsAddress(movements);
// cout << "OVERLOADED CONSTRUCTOR CALLED:" << endl;
}
// COPY_CONSTRUCTOR
account::account(const account &temp)
{
name = temp.name;
userName = temp.userName;
pin = temp.pin;
size = temp.size;
totalBalance = temp.totalBalance;
income = temp.income;
outcome = temp.outcome;
interest = temp.interest;
sort = temp.sort;
movements = temp.movements;
// cout << "COPY_CONSTRUCTOR CALLED:" << endl;
}
/* ========================================================
************************SETTERS***************************
========================================================*/
void account ::setName(string name) { this->name = name; }
void account ::setUserName(string userName) { this->userName = userName; }
void account ::setPin(int pin) { this->pin = pin; }
void account ::setSize(int size) { this->size = size; }
void account ::setTotalBalance(double totalBalance) { this->totalBalance = totalBalance; }
void account ::setIncome(double income) { this->income = income; }
void account ::setOutcome(double outcome) { this->outcome = outcome; }
void account ::setInterest(double interest) { this->interest = interest; }
void account ::setSort(bool sort) { this->sort = sort; }
void account ::setMovementsAddress(double *movements) { this->movements = movements; }
void account ::setMovementsValue()
{
movements = new double[size];
for (int i = 0; i < size; i++)
{
cin >> *(movements + i);
}
}
void account ::setData(string name, string userName, int pin, int size, double *movements, double totalBalance, double income, double outcome, double interest, bool sort)
{
setName(name);
setUserName(userName);
setPin(pin);
setSize(size);
setTotalBalance(totalBalance);
setIncome(income);
setOutcome(outcome);
setInterest(interest);
setSort(sort);
setMovementsAddress(movements);
}
/* ========================================================
************************GETTERS***************************
========================================================*/
string account ::getName() { return name; }
string account ::getUserName() { return userName; }
int account ::getPin() { return pin; }
int account ::getSize() { return size; }
double account ::getTotalBalance() { return totalBalance; }
double account ::getIncome() { return income; }
double account ::getOutcome() { return outcome; }
double account ::getInterest() { return interest; }
bool account ::getSort() { return sort; }
double *account ::getMovementsAddress() { return movements; }
void account ::getMovementsValue()
{
for (int i = 0; i < size; i++)
{
cout << *(movements + i) << endl;
}
}
void account ::getData()
{
cout << "\t\t Your name : " << name << endl;
cout << "\t\t Your userName : " << userName << endl;
cout << "\t\t Your pin code : " << pin << endl;
cout << "\t\t Your total Balance : " << totalBalance << endl;
cout << "\t\t Your total incomes : " << income << endl;
cout << "\t\t Your total outcomes : " << outcome << endl;
cout << "\t\t Your total interest amount : " << interest << endl;
spaces2();
cout << "\t\t\t *YOUR MOVEMENTS * " << endl;
spaces2();
for (int i = 0; i < size; i++)
{
if (*(movements + i) > 0)
cout << "\t\tDeposited : " << *(movements + i) << endl;
if (*(movements + i) < 0)
cout << "\t\tWithdrawl : " << *(movements + i) << endl;
}
cout << endl;
}
/* ========================================================
************************DESTRUCTOR*************************
========================================================*/
account ::~account()
{
// cout << "DESTRUCTOR CALLED:" << endl;
}
/* ========================================================
******************FUNCTIONALITY_FUNCTIONS******************
========================================================*/
//CREATING_ACCOUNT
void account ::createAccount()
{
cout << "\t\tEnter your full name = ";
getline(cin, name);
cout << "\t\tSet your pin code = ";
cin >> pin;
cout << "\t\t Are you want to deposit some balance now (y/n) :";
}
//CALCULATING_USER_NAME
void account ::calculateUserName()
{
userName = "";
userName.push_back(tolower(name[0]));
bool flag = false;
for (int i = 0; i < name.length(); i++)
{
if (name[i] == ' ')
{
flag = true;
}
if (name[i] != ' ' && flag == true)
{
userName.push_back(tolower(name[i]));
flag = false;
}
}
}
//CALCULATING_TOTAL_BALANCE
double account ::calculateTotalBalance()
{
double total = calculateTotalIncome() - calculateTotalOutcome();
totalBalance = total;
return total;
}
//CALCULATING_TOTAL_IN_COME_MOVEMENTS
double account ::calculateTotalIncome()
{
double totalIncome = 0.0;
for (int i = 0; i < size; i++)
{
if (*(movements + i) >= 0)
totalIncome += (*(movements + i));
}
income = totalIncome;
return totalIncome;
}
//CALCULATING_TOTAL_OUT_COME_MOVEMENTS
double account ::calculateTotalOutcome()
{
double totalOutcome = 0.0;
for (int i = 0; i < size; i++)
{
if (*(movements + i) < 0)
totalOutcome += (abs(*(movements + i)));
}
outcome = totalOutcome;
return totalOutcome;
}
//CALCULATING_TOTAL_INTEREST
double account ::calculateTotalInterest()
{
double totalInterest = 0.0;
for (int i = 0; i < size; i++)
{
double deposit = 0.0;
if (*(movements + i) > 0)
{
deposit = *(movements + i) * (interestRate / 100);
if (deposit >= 1)
{
totalInterest += deposit;
}
}
}
interest = totalInterest;
return totalInterest;
}
//SORTING_MOVEMENTS_________(ALGORITHUM::_SELECTION_SORT)
void account ::sortMovements()
{
int min_index;
for (int i = 0; i < size - 1; i++)
{
min_index = i;
for (int j = i + 1; j < size; j++)
{
if (*(movements + j) < *(movements + min_index))
{
min_index = j;
}
}
int temp;
temp = *(movements + i);
*(movements + i) = *(movements + min_index);
*(movements + min_index) = temp;
}
}