-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.cpp
More file actions
137 lines (111 loc) · 2.84 KB
/
Account.cpp
File metadata and controls
137 lines (111 loc) · 2.84 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
#include "Account.h"
#include "AccountImpl.h"
#include "FamilyAccount.h"
#include "StockAccount.h"
#include "TwoYearsAccount.h"
/****************
* CTOR & DTOR
****************/
Account::Account( Account_Type type, int date, Period period, float PrecentOnDeposit, int id)
{
m_Account = AccountFactory(type, date,period,PrecentOnDeposit, id);
}
Account::~Account()
{
delete m_Account;
m_Account = 0;
}
/*******************
* Bridge Wrappers
******************/
void Account::Update( Operation operation, int amount, string msg )
{
switch (operation)
{
case DEPOSIT:
deposit(amount);
break;
case WITHDRAWAL:
withdraw(amount);
break;
case DEPOSITSTOCK:
depositStock(amount);
break;
case NOTIFY:
notify(msg);
break;
}
}
ostream & operator<<( ostream &os, Account &acc )
{
return os << "Account id: " << acc.m_Account->GetId() << "\n"
<< "Account Type is " << acc.m_Account->GetAccountType() << " (0 - 2 years, 1- family, 2 - stock market)" << "\n"
<< "percent on deposit: " << acc.m_Account->GetPrecent() << "\n"
<< "Year of creation: " << acc.m_Account->GetDate() << "\n"
<< "Saving period: " << acc.m_Account->GetPeriod() << "\n"
<< "The bank last massage: " << acc.m_Account->GetLastMsg() << "\n"
<< "cash amount in the account: " << acc.m_Account->getAmount() << "\n"
<< "The Account is " << (acc.m_Account->IsClosed() ? "closed" : "open") << "\n";
}
AccountImpl* Account::AccountFactory( Account_Type type, int date, Period period, float PrecentOnDeposite, int id )
{
AccountImpl* account;
switch (type)
{
case TWOYEARS:
account = new TwoYearsAccount(PrecentOnDeposite,date,period, id);
break;
case FAMILY:
account = new FamilyAccount(PrecentOnDeposite,date,period, id);
break;
case STOCKEXCHANGE:
account = new StockAccount(PrecentOnDeposite,date,period, id);
break;
}
return account;
}
void Account::deposit( int amount )
{
m_Account->deposit(amount);
string str;
str += amount;
str += " deposit to the account";
m_Account->Notify(str);
}
void Account::withdraw( int amount )
{
float result;
result = m_Account->withdraw(amount);
string str;
str += (char) result;
str += " withdrawal from the account";
m_Account->Notify(str);
}
void Account::depositStock( int amount )
{
int result;
result = m_Account->InvestInStockMarket(amount);
string str;
str += (char) result;
str += " invested in the stock market";
m_Account->Notify(str);
}
void Account::notify( string msg )
{
m_Account->Notify(msg);
}
void Account::close(int currentDate)
{
bool result;
result = m_Account->Close(currentDate);
m_Account->Notify((result ? "the account were closed" : "unable to close the account"));
}
int Account::getDate() const{
return m_Account->GetDate();
}
int Account::getType() const{
return m_Account->GetAccountType();
}
Period Account::getPeriod() const {
return m_Account->GetPeriod();
}