-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrent.cpp
72 lines (61 loc) · 1.38 KB
/
current.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
#include "current.h"
#include "operation.h"
int Current::ourCount = 0;
const BigInteger Current::ourLeastBalance = 0;
const int Current::ourInterestRate = 0;
Current::Current(int ID, BigInteger cash, Date *dd, const string& name)
: myBalance(cash),
myName(name),
myInitialDate(dd),
myNumber(ourCount),
myID(ID)
{
ourCount++;
myOprs.push_back(new Operation(this, cash, CREATE, dd));
}
bool Current::Deposite(BigInteger cash, Date *dd)
{
if(dd < myInitialDate)
return false;
myBalance = myBalance + cash;
myOprs.push_back(new Operation(this, cash, DEPOSIT, dd));
return true;
}
bool Current::WithDraw(BigInteger cash, Date *dd)
{
if(dd < myInitialDate)
return false;
if(myBalance >= cash)
{
myBalance = myBalance - cash;
myOprs.push_back(new Operation(this, cash, WITH_DRAW, dd));
return true;
}
return false;
}
BigInteger Current::GetBalance()
{
return myBalance;
}
BigInteger Current::Benefit(Date * dd)
{
return 0;
}
int Current::GetID()
{
return myID;
}
string Current::ToString()
{
ostringstream out;
out << "Current Account (" << myID << ") " << myName << " " << myBalance;
return out.str();
}
string Current::DeepString()
{
ostringstream out;
out << *this;
for(int i = 0; i < myOprs.size(); i++)
out << *myOprs[i];
return out.str();
}