28ae19695b
Signed-off-by: Abdulkadir Furkan Şanlı <me@abdulocra.cy>
149 lines
2.7 KiB
C++
149 lines
2.7 KiB
C++
#include "bank.h"
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
double
|
|
Client::earn (const double amount)
|
|
{
|
|
underMattress += amount;
|
|
return amount;
|
|
}
|
|
|
|
double
|
|
Client::getMattress ()
|
|
{
|
|
return underMattress;
|
|
}
|
|
|
|
void
|
|
Bank::listClients ()
|
|
{
|
|
for (auto i : clients)
|
|
cout << "Name: " << i.id << " Current: " << i.current << endl;
|
|
cout << clients.size () << " accounts." << endl;
|
|
}
|
|
|
|
void
|
|
Bank::countEmployees ()
|
|
{
|
|
cout << employees.size () << " employees." << endl;
|
|
}
|
|
|
|
// Open account if enough employee capacity.
|
|
bool
|
|
Bank::openAccount (Client &x)
|
|
{
|
|
if (employees.size () == 0)
|
|
return false;
|
|
if (employees.size () * CLIENT_EMPLOYEE <= clients.size ())
|
|
return false;
|
|
for (auto i : x.accounts)
|
|
if (i == this)
|
|
return false;
|
|
|
|
clientRecord newClient;
|
|
newClient.id = x.id;
|
|
clients.push_back (newClient);
|
|
x.accounts.push_back (this);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
Bank::hire (Employee &x)
|
|
{
|
|
if (x.employer != nullptr)
|
|
return false;
|
|
employees.push_back (&x);
|
|
x.employer = this;
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
Bank::fire (Employee &x)
|
|
{
|
|
if (x.employer != this)
|
|
return false;
|
|
for (auto i = employees.begin (); i != employees.end (); i++)
|
|
if (*i == &x)
|
|
{
|
|
employees.erase (i);
|
|
x.employer = nullptr;
|
|
return true;
|
|
}
|
|
cout << "Bank doesn't have employee listed, but employee does." << endl;
|
|
exit (EXIT_FAILURE);
|
|
}
|
|
|
|
// Deposit money from under the mattress, return amount.
|
|
double
|
|
Bank::deposit (Client &x, const double amount)
|
|
{
|
|
if (amount == 0)
|
|
return 0;
|
|
if (x.underMattress < amount)
|
|
return 0;
|
|
for (auto i = clients.begin(); i != clients.end(); i++)
|
|
if (i->id == x.id)
|
|
{
|
|
x.underMattress -= amount;
|
|
i->current += amount;
|
|
current += amount;
|
|
return amount;
|
|
}
|
|
cout << "Client doesn't have an account at bank." << endl;
|
|
return 0;
|
|
}
|
|
|
|
double
|
|
Bank::getCurrent (const Client &x)
|
|
{
|
|
for (auto i : clients)
|
|
if (i.id == x.id)
|
|
return i.current;
|
|
cout << "Client doesn't have an account at bank." << endl;
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
Gov::associate (Bank *const x)
|
|
{
|
|
banks.push_back (x);
|
|
}
|
|
|
|
int
|
|
main ()
|
|
{
|
|
Client abdul ("abdul");
|
|
abdul.earn (666);
|
|
|
|
Employee dude ("dude");
|
|
Employee gal ("gal");
|
|
|
|
Gov fed;
|
|
Bank boa (&fed);
|
|
|
|
boa.countEmployees ();
|
|
|
|
boa.hire (dude);
|
|
boa.countEmployees ();
|
|
boa.fire (gal);
|
|
boa.countEmployees ();
|
|
boa.fire (dude);
|
|
boa.countEmployees ();
|
|
boa.hire (gal);
|
|
boa.hire (dude);
|
|
boa.countEmployees ();
|
|
|
|
boa.openAccount (abdul);
|
|
boa.listClients ();
|
|
|
|
cout << abdul.getMattress () << " under mattress." << endl;
|
|
boa.deposit (abdul, 500);
|
|
cout << boa.getCurrent (abdul) << " in bank account." << endl;
|
|
cout << abdul.getMattress () << " under mattress." << endl;
|
|
|
|
return 0;
|
|
}
|