124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
#include <iostream>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <random>
|
|
#include <ctime>
|
|
#include "HeapObject.h"
|
|
#include "CashFactory.h"
|
|
#include "Bank.h"
|
|
|
|
std::default_random_engine generator(static_cast<unsigned long>(time(nullptr)));
|
|
std::uniform_int_distribution<int> distribution(-100, 500);
|
|
|
|
std::string currency_to_string(CurrencyValue value) {
|
|
if (value == CurrencyValue::USD) return "US Dollar";
|
|
if (value == CurrencyValue::EUR) return "Euro";
|
|
if (value == CurrencyValue::GPD) return "British Pound";
|
|
return "Say what ?";
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Currency currency) {
|
|
os << currency_to_string(currency.getValue());
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Bill bill) {
|
|
os << bill.getValue() << " " << bill.getCurrency() << " " << bill.getSerial();
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Cash cash) {
|
|
os << cash.getValue() << " " << cash.getCurrency();
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Money money) {
|
|
os << money.getValue() << " " << money.getCurrency();
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Person *person) {
|
|
os << person->getName();
|
|
return os;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, BankAccount bankAccount) {
|
|
os << bankAccount.getOwner() << " " << bankAccount.getName() << ": " << bankAccount.getMoney();
|
|
return os;
|
|
}
|
|
|
|
std::set<std::unique_ptr<Bank>> banks;
|
|
|
|
void setup() {
|
|
|
|
std::unique_ptr<Bank> bank1 = std::make_unique<Bank>(new Bank("Bank 1"));
|
|
std::unique_ptr<Bank> bank2 = std::make_unique<Bank>(new Bank("Bank 2"));
|
|
std::unique_ptr<Bank> bank3 = std::make_unique<Bank>(new Bank("Bank 3"));
|
|
|
|
std::shared_ptr<Person> max = std::make_shared<Person>(new Person("Max Müller"));
|
|
std::shared_ptr<Person> marius = std::make_shared<Person>(new Person("Marius Müller"));
|
|
std::shared_ptr<Person> alex = std::make_shared<Person>(new Person("Alex Maier"));
|
|
|
|
|
|
bank1->addAccount(new BankAccount(max, "Konto 1"));
|
|
bank2->addAccount(new BankAccount(max, "Konto 2"));
|
|
bank1->addAccount(new BankAccount(alex, "privat"));
|
|
bank3->addAccount(new BankAccount(alex, "geschäftlich 1"));
|
|
bank2->addAccount(new BankAccount(alex, "geschäftlich 2"));
|
|
bank1->addAccount(new BankAccount(alex, "geschäftlich 3"));
|
|
bank2->addAccount(new BankAccount(marius, "Konto 1"));
|
|
bank1->addAccount(new BankAccount(marius, "Konto 2"));
|
|
bank3->addAccount(new BankAccount(marius, "Konto 3"));
|
|
|
|
banks.insert(std::move(bank1));
|
|
banks.insert(std::move(bank2));
|
|
banks.insert(std::move(bank3));
|
|
}
|
|
|
|
void simulate() {
|
|
auto *cashFactory = new CashFactory();
|
|
|
|
for (auto && bank : banks) {
|
|
std::cout << std::endl;
|
|
std::cout << "======================== " << bank->getName() << " ========================" << std::endl;
|
|
std::cout << std::endl;
|
|
for (BankAccount *bankAccount : bank->getAccounts()) {
|
|
for (int i = 0; i < 10000; ++i) {
|
|
int rnd = distribution(generator);
|
|
Bill *bill = cashFactory->printBill(rnd, CurrencyValue::USD);
|
|
Coin *coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
|
|
if (bill != nullptr) {
|
|
*bankAccount + bill;
|
|
}
|
|
if (coin != nullptr) {
|
|
*bankAccount + coin;
|
|
}
|
|
|
|
Money *fee = *bankAccount - 10;
|
|
}
|
|
std::cout << *bankAccount << std::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
void tearDown() {
|
|
for (auto && bank : banks) {
|
|
for (BankAccount *bankAccount : bank->getAccounts()) {
|
|
delete(bankAccount);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
std::cout << "+++++++++++++++++++++++++ " << "setup()" << " +++++++++++++++++++++++++" << std::endl;
|
|
setup();
|
|
std::cout << "+++++++++++++++++++++++++ " << "simulate()" << " +++++++++++++++++++++++++" << std::endl;
|
|
simulate();
|
|
std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl;
|
|
tearDown();
|
|
|
|
HeapObject::assertionsHold();
|
|
|
|
return 0;
|
|
} |