-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.hpp
More file actions
262 lines (190 loc) · 6.3 KB
/
account.hpp
File metadata and controls
262 lines (190 loc) · 6.3 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
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
//
// account.hpp
// Test Product
//
// Created by David Brown on 05/06/2017.
// Copyright © 2017 David Brown. All rights reserved.
//
#ifndef account_hpp
#define account_hpp
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <list>
#include "settings.hpp"
#include "statistics.hpp"
#include "register.hpp"
// Account is the base class for every active entity in the system
// and provides the basic overrideable functionality.
class Statistics;
class Settings;
class Firm;
class Government;
class Account
{
public:
Account();
virtual int getBalance();
// This function is declared as virtual to allow derived class
// to add functionality, e.g. diagnostics
virtual void credit(int amount, Account *creditor = nullptr);
// Every derived class must provide a trigger function,
// which will be called once per period.
virtual void trigger(int period) = 0;
int getId() const;
protected:
Register *reg;
Settings *settings;
Statistics *stats;
// We can't have an instance of Government as a member of Account because
// Government is derived from Account
// Government *gov;
int balance;
int last_triggered = -1;
bool transferTo(Account *recipient, int amount, Account *creditor);
private:
int id;
};
// The Firm class is used in Worker, which it also uses, so we
// need a forward declaration here.
//class Register;
class Worker: public Account
{
friend class Government;
friend class Firm;
friend class Register;
private:
int wage;
Firm *employer;
// Receipts and payments for current period only. Must be
// set to zero on each trigger (unless re-triggered in same
// period) and accumulated throughout period. 'Get' methods
// must be used to retrieve these values at the end of each
// period for statistics.
int purchases;
int benefits;
int wages;
int inc_tax;
int period_hired;
int period_fired;
protected:
Government *gov;
void init();
void setEmployer(Firm*);
void setPeriodHired(int period);
public:
Worker(int wage, Firm *emp, int period);
Worker();
Firm *getEmployer();
bool isEmployed();
bool isEmployedBy(Account *emp);
bool isNewHire(int period);
// Overrides
void credit(int amount, Account *creditor = nullptr);
void trigger(int period);
int getWagesReceived();
int getBenefitsReceived();
int getPurchasesMade();
int getIncTaxPaid();
};
class Firm: public Account
{
friend class Government;
friend class Register;
private:
int std_wage;
int amount_granted = 0;
int wages_paid = 0;
int bonuses_paid = 0;
int sales_tax_paid = 0;
int sales_receipts = 0;
int dedns_paid = 0;
int num_hired = 0;
int num_fired = 0;
int committed = 0; // current cost of wages and deductions
protected:
Government *gov;
// Only government can make a grant, so this should be protected
// and the Government class made a friend class
void grant(int amount);
void init();
public:
// RATIONALE
// ---------
// We consider a year to be made up of 50 periods and a
// typical yearly wage to be 25000 -- i.e. 500 per period.
// Initially we will assume everyone is paid the same
// amount, but we will need to allow different schemes,
// such as random with even distribution, random with
// normal distribution, and random with lognormal
// distribution. The latter seems to give a fairly
// convincing 'long-tail' distribution.
//
// A distribution based on recorded peercentile
// figures for the UK in 2015 approximates to the
// polynomial:
//
// 0.00001229(x^6) + 0.0033(x^5) + 0.3373(x^4) + 16.066(x^3) + 359
//
// where 0 < x < 100 is the percentile. It should be possible
// to work out a distribution function that would produce
// this result. The table itself can be found at
//
// https://www.gov.uk/government/statistics/percentile-points-from-1-to-99-for-total-income-before-and-after-tax
//
// and it might be more straightforward to base wages on
// that. An alternative approach would be to start off with
// equal (or evenly distributed) wages and see what
// develops over time.
Firm(int standard_wage = 500);
void trigger(int period);
void epilogue(int period);
// Overrides base mmethod to give additional functionality
void credit(int amount, Account *creditor = nullptr);
int getAmountGranted();
int getWagesPaid();
int getBonusesPaid();
int getSalesTaxPaid();
int getSalesReceipts();
int getDednsPaid();
size_t getNumEmployees();
int getNumHired();
int getNumFired();
};
// Government is a singleton class as we are currently assuming
// a closed economy wth a single currency. Foreign trade would
// require firms that were registered to a different Government.
// This should be added later.
class Government: public Account
{
private:
static Government *_instance;
Firm *gov_firm; // (see constructor for assignment to firms)
Register *reg;
int exp, rec, ben;
protected:
Government();
void init();
// This method overrides the method in the base (Account) class, which
// prohibits transfers that would leave a negative balance. This
// restriction doesn't apply to the government, which creates money
// precisely by creating transfers that leave a negative balance.
void transferTo(Account *recipient,
int amount,
Account *creditor
);
// We override the base method here just so we can extract
// the balance for statistics.
void credit(int amount, Account *creditor = nullptr);
public:
static Government *Instance();
void trigger(int period);
int getExpenditure(); // Gov expenditure in current period (excl benefits)
int getBenefitsPaid(); // Benefits paid this period
int getReceipts(); // Gov receipts (taxes and dedns) in current period
size_t getNumEmployees(); // Number of government employees
};
class Bank: public Account
{
};
#endif /* account_hpp */