28ae19695b
Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
99 lines
2.3 KiB
C++
99 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <ctime>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class Bank;
|
|
class Client;
|
|
class Employee;
|
|
class Gov;
|
|
|
|
class Gov
|
|
{
|
|
public:
|
|
int factor = 6; // Money multiplier.
|
|
int rate = 2; // Interest rate (%).
|
|
time_t last_bailout = 0; // Time since last bailout.
|
|
void associate (Bank *const x);
|
|
bool disassociate (Bank *const x);
|
|
double reserveDeposit (const Bank &x, const double amount);
|
|
double reserveWithdraw (const Bank &x, const double amount);
|
|
bool bailout (const Bank &x, double amount);
|
|
|
|
private:
|
|
double bankReserves = 0;
|
|
std::vector<Bank *> banks;
|
|
};
|
|
|
|
class Bank
|
|
{
|
|
friend class Gov;
|
|
|
|
public:
|
|
Gov *centralBank;
|
|
Bank (Gov *x) : centralBank (x) { x->associate (this); };
|
|
double deposit (Client &x, const double amount);
|
|
double withdraw (Client &x, const double amount);
|
|
double getCurrent (const Client &x);
|
|
bool hire (Employee &x);
|
|
bool fire (Employee &x);
|
|
bool openAccount (Client &x);
|
|
bool newCredit (const std::string id, const double amount,
|
|
const int installments, const int days,
|
|
const float interest); // interest is additional interest on
|
|
// top of Gov rate.
|
|
double payInstallment (const int index);
|
|
void countEmployees ();
|
|
void listClients ();
|
|
|
|
private:
|
|
const int CLIENT_EMPLOYEE = 2; // Max number of clients to employees.
|
|
double current = 0; // Total current accts. of clients.
|
|
double creditable = 0; // Amount able to be loaned to clients.
|
|
double credited = 0; // Amount loaned.
|
|
struct creditRecord
|
|
{
|
|
time_t start;
|
|
long interval; // Interval of payments in number of seconds.
|
|
double amount;
|
|
int installments;
|
|
float interest;
|
|
};
|
|
struct clientRecord
|
|
{
|
|
std::string id;
|
|
double current = 0;
|
|
std::vector<creditRecord> loans;
|
|
};
|
|
std::vector<clientRecord> clients;
|
|
std::vector<Employee *> employees;
|
|
};
|
|
|
|
class Employee
|
|
{
|
|
friend class Bank;
|
|
|
|
public:
|
|
std::string name;
|
|
Employee (std::string x) : name (x){};
|
|
|
|
private:
|
|
Bank *employer = nullptr;
|
|
};
|
|
|
|
class Client
|
|
{
|
|
friend class Bank;
|
|
|
|
public:
|
|
std::string id;
|
|
Client (std::string x) : id (x), underMattress (0){};
|
|
double earn (const double amount); // Earn money.
|
|
double getMattress ();
|
|
|
|
private:
|
|
double underMattress;
|
|
std::vector<Bank *> accounts;
|
|
};
|