From 5c46cc3d66928bc23916fb5dd4febd41c5dd70dc Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 2 Jan 2019 15:29:11 +0100 Subject: [PATCH] 10_PITF: Wieder auf Anfang --- src/08_PTRN/Testat/main.cpp | 28 ++------ src/10_PITF/CMakeLists.txt | 2 +- src/10_PITF/Testat/Bank.cpp | 20 ++---- src/10_PITF/Testat/Bank.h | 16 ++--- src/10_PITF/Testat/BankAccount.cpp | 47 +++--------- src/10_PITF/Testat/BankAccount.h | 24 +++---- src/10_PITF/Testat/Bill.cpp | 8 --- src/10_PITF/Testat/Bill.h | 2 - src/10_PITF/Testat/Cash.h | 3 +- src/10_PITF/Testat/CashFactory.cpp | 12 ++-- src/10_PITF/Testat/CashFactory.h | 6 +- src/10_PITF/Testat/Coin.cpp | 10 +-- src/10_PITF/Testat/Coin.h | 4 +- src/10_PITF/Testat/Currency.cpp | 2 +- src/10_PITF/Testat/Currency.h | 2 +- src/10_PITF/Testat/HeapObject.cpp | 4 +- src/10_PITF/Testat/Money.cpp | 56 ++++++--------- src/10_PITF/Testat/Money.h | 23 +++--- src/10_PITF/Testat/Person.cpp | 6 +- src/10_PITF/Testat/Person.h | 7 +- src/10_PITF/Testat/main.cpp | 110 +++++++++++++---------------- 21 files changed, 141 insertions(+), 251 deletions(-) diff --git a/src/08_PTRN/Testat/main.cpp b/src/08_PTRN/Testat/main.cpp index 3d56c57..6438d40 100644 --- a/src/08_PTRN/Testat/main.cpp +++ b/src/08_PTRN/Testat/main.cpp @@ -100,27 +100,11 @@ int main(int argc, char **argv) { } } - /* - * Schmeißt nen SIGSERV/SEGFAULT - * std::for_each(banks.begin(), banks.end(), [cashFactory] (Bank * bank) { - std::for_each(bank->getAccounts().begin(), bank->getAccounts().end(), [cashFactory] (BankAccount * bankAccount) { - std::cout << *bankAccount << std::endl; - 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; - } - delete bill; - delete coin; - } - std::cout << *bankAccount << std::endl; - }); - }); - */ + for (Bank *bank : banks) { + for (BankAccount *bankAccount : bank->getAccounts()) { + delete(bankAccount); + } + delete(bank); + } } \ No newline at end of file diff --git a/src/10_PITF/CMakeLists.txt b/src/10_PITF/CMakeLists.txt index bf3cd9f..4b8f681 100644 --- a/src/10_PITF/CMakeLists.txt +++ b/src/10_PITF/CMakeLists.txt @@ -1 +1 @@ -add_executable(10_PITF_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h Testat/Currency.h Testat/BankAccount.cpp Testat/BankAccount.h Testat/Cash.cpp Testat/Cash.h Testat/Currency.cpp Testat/Coin.cpp Testat/Coin.h Testat/Bill.cpp Testat/Bill.h Testat/CashFactory.h Testat/Person.cpp Testat/Person.h Testat/CashFactory.cpp Testat/Bank.cpp Testat/Bank.h Testat/HeapObject.h Testat/HeapObject.cpp) +add_executable(10_PITF_Testat Testat/main.cpp Testat/HeapObject.h Testat/HeapObject.cpp Testat/Bank.cpp Testat/BankAccount.cpp Testat/Money.cpp Testat/Coin.cpp Testat/Cash.cpp Testat/Currency.cpp Testat/CashFactory.cpp Testat/Person.cpp Testat/Bill.cpp) diff --git a/src/10_PITF/Testat/Bank.cpp b/src/10_PITF/Testat/Bank.cpp index 6c71edc..bd2002e 100644 --- a/src/10_PITF/Testat/Bank.cpp +++ b/src/10_PITF/Testat/Bank.cpp @@ -3,24 +3,15 @@ #include "Bank.h" -Bank::Bank(std::string const& name) : name(name) { +Bank::Bank(std::string name) : name(std::move(name)) { } -Bank::Bank(Bank* bank) : name(bank->name) { - money.swap(bank->money); - accounts.swap(bank->accounts); +void Bank::addAccount(BankAccount * account) { + accounts.insert(account); } -void Bank::addAccount(std::shared_ptr account) { - this->accounts.insert(std::move(account)); -} - -void Bank::addMoney(std::shared_ptr money) { - this->money.insert(std::move(money)); -} - -std::set> Bank::getAccounts() { +std::set Bank::getAccounts() { return accounts; } @@ -28,4 +19,7 @@ std::string Bank::getName() { return name; } +void Bank::addMoney(Money * money) { + this->money.insert(money); +} diff --git a/src/10_PITF/Testat/Bank.h b/src/10_PITF/Testat/Bank.h index 97c15c8..3dde3e3 100644 --- a/src/10_PITF/Testat/Bank.h +++ b/src/10_PITF/Testat/Bank.h @@ -3,18 +3,18 @@ #include "BankAccount.h" +#include "HeapObject.h" -class Bank { +class Bank : public HeapObject{ private: std::string name; - std::set> accounts; - std::set> money; + std::set accounts; + std::set money; public: - explicit Bank(std::string const& name); - explicit Bank(Bank* bank); - void addAccount(std::shared_ptr account); - void addMoney(std::shared_ptr money); - std::set> getAccounts(); + explicit Bank(std::string name); + void addAccount(BankAccount * account); + void addMoney(Money * money); + std::set getAccounts(); std::string getName(); }; diff --git a/src/10_PITF/Testat/BankAccount.cpp b/src/10_PITF/Testat/BankAccount.cpp index c1a8ed7..bb970d7 100644 --- a/src/10_PITF/Testat/BankAccount.cpp +++ b/src/10_PITF/Testat/BankAccount.cpp @@ -1,59 +1,34 @@ -#include - -#include -#include - #include "BankAccount.h" #include "CashFactory.h" -BankAccount::BankAccount(std::shared_ptr const& owner, std::string const& name) : name(name), owner(std::move(owner)) { - +BankAccount::BankAccount(Person * owner, std::string name) : name(std::move(name)) { +this->owner = owner; } -BankAccount::BankAccount(BankAccount *bankAccount) : name(bankAccount->name) { - money.swap(bankAccount->money); - owner.swap(bankAccount->owner); +BankAccount * BankAccount::operator+(Money * money) { + + BankAccount::money = new Money(money->getValue() + getMoney().getValue()); + return this; } -BankAccount::BankAccount(BankAccount &bankAccount) : name(bankAccount.name) { - money.swap(bankAccount.money); - owner.swap(bankAccount.owner); -} - -std::shared_ptr BankAccount::operator+(std::shared_ptr money) { - - this->money->setValue(this->money->getValue() + money->getValue()); - - return std::make_shared(*this); -} - -std::shared_ptr BankAccount::operator+(std::shared_ptr money) { - std::shared_ptr ptr = std::make_shared(new Money(money->getValue() + this->money->getValue(), money->getCurrency())); - - BankAccount::money = ptr; - - return std::make_shared(*this); -} - -std::shared_ptr BankAccount::operator-(int value) { +Money * BankAccount::operator-(int value) { auto * cashFactory = new CashFactory(); return cashFactory->printCoin(value, CurrencyValue::USD); } - -bool BankAccount::operator<(std::shared_ptr bankAccount) { - return this->money->getValue() < bankAccount->money->getValue(); +bool BankAccount::operator<(BankAccount * bankAccount) { + return money.getValue() < bankAccount->money.getValue(); } std::string BankAccount::getName() { return name; } -std::shared_ptr BankAccount::getMoney() { +Money BankAccount::getMoney() { return money; } -std::shared_ptr BankAccount::getOwner() { +Person *BankAccount::getOwner() { return owner; } diff --git a/src/10_PITF/Testat/BankAccount.h b/src/10_PITF/Testat/BankAccount.h index b7d887a..c0432ad 100644 --- a/src/10_PITF/Testat/BankAccount.h +++ b/src/10_PITF/Testat/BankAccount.h @@ -1,27 +1,25 @@ #ifndef C_C_BANKACCOUNTS_H #define C_C_BANKACCOUNTS_H +#include + #include "Money.h" +#include "Cash.h" #include "Person.h" -#include "Coin.h" -#include "Bill.h" class BankAccount { private: std::string name; - std::shared_ptr owner; - std::shared_ptr money; + Person * owner; + Money money; public: - explicit BankAccount(std::shared_ptr const& owner, std::string const& name); - explicit BankAccount(BankAccount *bankAccount); - BankAccount(BankAccount& bankAccount); - std::shared_ptr operator+(std::shared_ptr money); - std::shared_ptr operator+(std::shared_ptr money); - std::shared_ptr operator-(int value); - bool operator<(std::shared_ptr bankAccount); + explicit BankAccount(Person * owner, std::string name); + BankAccount* operator+(Money * money); + Money* operator-(int value); + bool operator<(BankAccount * bankAccount); std::string getName(); - std::shared_ptr getOwner(); - std::shared_ptr getMoney(); + Person * getOwner(); + Money getMoney(); }; diff --git a/src/10_PITF/Testat/Bill.cpp b/src/10_PITF/Testat/Bill.cpp index c6d885f..de9d70b 100644 --- a/src/10_PITF/Testat/Bill.cpp +++ b/src/10_PITF/Testat/Bill.cpp @@ -6,14 +6,6 @@ Bill::Bill(int value, Currency currency, std::string serial) : Cash(value, curre } -Bill::Bill(Bill *bill) : Cash(bill->getValue(), bill->getCurrency()), serial(bill->getSerial()){ - -} - -Currency Bill::getCurrency() { - return Money::getCurrency(); -} - int Bill::getValue() { return Money::getValue() * 10; } diff --git a/src/10_PITF/Testat/Bill.h b/src/10_PITF/Testat/Bill.h index 60a83e4..bafd05e 100644 --- a/src/10_PITF/Testat/Bill.h +++ b/src/10_PITF/Testat/Bill.h @@ -9,9 +9,7 @@ private: std::string serial; public: Bill(int value, Currency currency, std::string serial); - explicit Bill(Bill *bill); std::string getSerial(); - Currency getCurrency(); int getValue(); }; diff --git a/src/10_PITF/Testat/Cash.h b/src/10_PITF/Testat/Cash.h index 7cc9587..bbf3f5d 100644 --- a/src/10_PITF/Testat/Cash.h +++ b/src/10_PITF/Testat/Cash.h @@ -1,10 +1,11 @@ #ifndef C_C_CASH_H #define C_C_CASH_H +#include #include "Money.h" #include "HeapObject.h" -class Cash : public HeapObject, public Money{ +class Cash : public Money, public HeapObject{ private: public: Cash(int value, Currency currency); diff --git a/src/10_PITF/Testat/CashFactory.cpp b/src/10_PITF/Testat/CashFactory.cpp index 89e6d54..0eff08f 100644 --- a/src/10_PITF/Testat/CashFactory.cpp +++ b/src/10_PITF/Testat/CashFactory.cpp @@ -1,5 +1,4 @@ #include -#include #include "CashFactory.h" int allowedBills[5] = {100, 50, 20, 10, 5}; @@ -7,8 +6,7 @@ int allowedCoins[8] = {1, 2, 5, 10, 20, 50, 100, 200}; std::vector usedSerials; -std::shared_ptr CashFactory::printBill(int value, Currency currency) { - std::cout << "Test" << std::endl; +Bill * CashFactory::printBill(int value, Currency currency) { auto * iter = std::find(std::begin(allowedBills), std::end(allowedBills), value); if(iter == std::end(allowedBills)) { return nullptr; @@ -18,17 +16,15 @@ std::shared_ptr CashFactory::printBill(int value, Currency currency) { serial = randomString(15); } usedSerials.push_back(serial); - - std::cout << "Test2" << std::endl; - return std::make_shared(new Bill(value, currency, serial)); + return new Bill(value, currency, serial); } } -std::shared_ptr CashFactory::printCoin(int value, Currency currency) { +Coin * CashFactory::printCoin(int value, Currency currency) { auto * iter = std::find(std::begin(allowedCoins), std::end(allowedCoins), value); if(iter == std::end(allowedCoins)) { return nullptr; - }else return std::make_shared(new Coin(value, currency)); + }else return new Coin(value, currency); } std::string CashFactory::randomString(size_t length) { diff --git a/src/10_PITF/Testat/CashFactory.h b/src/10_PITF/Testat/CashFactory.h index 321edfb..59b33b0 100644 --- a/src/10_PITF/Testat/CashFactory.h +++ b/src/10_PITF/Testat/CashFactory.h @@ -3,8 +3,6 @@ #include #include -#include - #include "Bill.h" #include "Coin.h" @@ -12,8 +10,8 @@ class CashFactory { private: std::string randomString(size_t length); public: - std::shared_ptr printBill(int value, Currency currency); - std::shared_ptr printCoin(int value, Currency currency); + Bill * printBill(int value, Currency currency); + Coin * printCoin(int value, Currency currency); }; #endif \ No newline at end of file diff --git a/src/10_PITF/Testat/Coin.cpp b/src/10_PITF/Testat/Coin.cpp index 50da068..f7d15cb 100644 --- a/src/10_PITF/Testat/Coin.cpp +++ b/src/10_PITF/Testat/Coin.cpp @@ -4,14 +4,6 @@ Coin::Coin(int value, Currency currency) : Cash(value, currency) { } -Coin::Coin(Coin *coin) : Cash(coin->getValue(), coin->getCurrency()) { - -} - -Currency Coin::getCurrency() { - return Money::getCurrency(); -} - int Coin::getValue() { return Money::getValue(); -} +} \ No newline at end of file diff --git a/src/10_PITF/Testat/Coin.h b/src/10_PITF/Testat/Coin.h index 5a61834..9195945 100644 --- a/src/10_PITF/Testat/Coin.h +++ b/src/10_PITF/Testat/Coin.h @@ -8,9 +8,7 @@ class Coin : public Cash{ private: public: Coin(int value, Currency currency); - explicit Coin(Coin *coin); - Currency getCurrency(); - int getValue(); + int getValue() override; }; #endif diff --git a/src/10_PITF/Testat/Currency.cpp b/src/10_PITF/Testat/Currency.cpp index f73472e..181d96d 100644 --- a/src/10_PITF/Testat/Currency.cpp +++ b/src/10_PITF/Testat/Currency.cpp @@ -4,7 +4,7 @@ Currency::Currency(CurrencyValue value) : value(value) { } -bool Currency::operator==(Currency currency) { +bool Currency::operator==(Currency ¤cy) { return value == currency.value; } diff --git a/src/10_PITF/Testat/Currency.h b/src/10_PITF/Testat/Currency.h index d511519..469346c 100644 --- a/src/10_PITF/Testat/Currency.h +++ b/src/10_PITF/Testat/Currency.h @@ -14,7 +14,7 @@ private: CurrencyValue value; public: Currency(CurrencyValue value); - bool operator==(Currency currency); + bool operator==(Currency ¤cy); Currency& operator=(Currency currency); CurrencyValue getValue(); diff --git a/src/10_PITF/Testat/HeapObject.cpp b/src/10_PITF/Testat/HeapObject.cpp index da29371..080327e 100644 --- a/src/10_PITF/Testat/HeapObject.cpp +++ b/src/10_PITF/Testat/HeapObject.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "HeapObject.h" int HeapObject::ctorCount = 0; @@ -21,6 +22,7 @@ HeapObject::~HeapObject(){ bool HeapObject::assertionsHold(){ assert(ctorCount == newCount); // all objects have been allocated on heap - //assert(ctorCount == dtorCount); // all objects have been deleted + std::cout << ctorCount << " == " << dtorCount << std::endl; + assert(ctorCount == dtorCount); // all objects have been deleted return true; } diff --git a/src/10_PITF/Testat/Money.cpp b/src/10_PITF/Testat/Money.cpp index 0775bfd..841269d 100644 --- a/src/10_PITF/Testat/Money.cpp +++ b/src/10_PITF/Testat/Money.cpp @@ -1,61 +1,45 @@ -#include #include "Money.h" Money::Money(int value, Currency currency) : value(value), currency(currency) { + } -Money::Money(Money *money) : value(money->value), currency(money->currency) { - std::cout << "Test2" << std::endl; -} - -std::shared_ptr Money::operator=(Money money) { +Money& Money::operator=(Money money) { value = money.getValue(); currency = money.getCurrency(); - return std::make_shared(*this); + return *this; } -std::shared_ptr Money::operator+(Money &a) { +Money &Money::operator=(Money *money) { + value = money->getValue(); + currency = money->getCurrency(); + return *this; +} + +Money Money::operator+(Money &a) { if(currency == a.currency) { - return std::make_shared(Money(value + a.value, CurrencyValue::USD)); - }else return std::make_shared(Money(-1, Currency(CurrencyValue::USD))); + return Money(value + a.value); + }else return Money(-1, Currency(CurrencyValue::USD)); } -std::shared_ptr Money::operator+(Bill &a) { - if(currency == a.getCurrency()) { - return std::make_shared(Money(value + a.getValue(), CurrencyValue::USD)); - }else return std::make_shared(Money(-1, Currency(CurrencyValue::USD))); -} - -std::shared_ptr Money::operator+(Coin &a) { - if(currency == a.getCurrency()) { - return std::make_shared(Money(value + a.getValue(), CurrencyValue::USD)); - }else return std::make_shared(Money(-1, Currency(CurrencyValue::USD))); -} - -std::shared_ptr Money::operator-(Money &a) { +Money Money::operator-(Money &a) { if(currency == a.currency) { - return std::make_unique(Money(value - a.value, CurrencyValue::USD)); - }else return std::make_unique(Money(-1, Currency(CurrencyValue::USD))); + return Money(value - a.value); + }else return Money(-1, Currency(CurrencyValue::USD)); } -const std::shared_ptr Money::operator++(int) { - value++; - return std::make_unique(*this); +const Money Money::operator++(int) { + return Money(value++); } -const std::shared_ptr Money::operator--(int) { - value--; - return std::make_unique(*this); +const Money Money::operator--(int) { + return Money(value--); } int Money::getValue() { return value; } -void Money::setValue(int value) { - this->value = value; -} - Currency Money::getCurrency() { return currency; -} +} \ No newline at end of file diff --git a/src/10_PITF/Testat/Money.h b/src/10_PITF/Testat/Money.h index 4d583e3..ddfa6f1 100644 --- a/src/10_PITF/Testat/Money.h +++ b/src/10_PITF/Testat/Money.h @@ -1,30 +1,23 @@ #ifndef C_C_MONEY_H #define C_C_MONEY_H -#include - #include "Currency.h" -#include "Bill.h" -#include "Coin.h" class Money { private: int value; Currency currency; public: - explicit Money(int value, Currency currency); - explicit Money(Money* money); - std::shared_ptr operator=(Money money); - std::shared_ptr operator+(Money &a); - std::shared_ptr operator+(Bill &a); - std::shared_ptr operator+(Coin &a); - std::shared_ptr operator-(Money &a); - const std::shared_ptr operator++(int); - const std::shared_ptr operator--(int); + explicit Money(int value = 0, Currency currency = CurrencyValue::USD); + Money& operator=(Money money); + Money& operator=(Money * money); + Money operator+(Money &a); + Money operator-(Money &a); + const Money operator++(int); + const Money operator--(int); virtual int getValue(); - virtual void setValue(int value); - virtual Currency getCurrency(); + Currency getCurrency(); }; #endif diff --git a/src/10_PITF/Testat/Person.cpp b/src/10_PITF/Testat/Person.cpp index 6bc3054..c33c5e1 100644 --- a/src/10_PITF/Testat/Person.cpp +++ b/src/10_PITF/Testat/Person.cpp @@ -2,14 +2,10 @@ #include "Person.h" -Person::Person(std::string const& name) : name(name) { +Person::Person(std::string name) : name(std::move(name)){ } -Person::Person(Person *person) : name(person->name) { - money.swap(person->money); -} - std::string Person::getName() { return name; } \ No newline at end of file diff --git a/src/10_PITF/Testat/Person.h b/src/10_PITF/Testat/Person.h index 17a3fd3..ffd9656 100644 --- a/src/10_PITF/Testat/Person.h +++ b/src/10_PITF/Testat/Person.h @@ -3,17 +3,14 @@ #include -#include - #include "Money.h" class Person { private: std::string name; - std::vector> money; + std::vector money; public: - explicit Person(std::string const& name); - explicit Person(Person* person); + explicit Person(std::string name); std::string getName(); }; diff --git a/src/10_PITF/Testat/main.cpp b/src/10_PITF/Testat/main.cpp index 2776586..8bbd9e5 100644 --- a/src/10_PITF/Testat/main.cpp +++ b/src/10_PITF/Testat/main.cpp @@ -1,11 +1,9 @@ -#include -#include + #include -#include +#include #include -#include "Currency.h" -#include "BankAccount.h" -#include "Bill.h" +#include +#include "HeapObject.h" #include "CashFactory.h" #include "Bank.h" @@ -24,99 +22,93 @@ std::ostream &operator<<(std::ostream &os, Currency currency) { return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr const& bill) { - os << bill->getValue() << " " << bill->getCurrency() << " " << bill->getSerial(); +std::ostream &operator<<(std::ostream &os, Bill bill) { + os << bill.getValue() << " " << bill.getCurrency() << " " << bill.getSerial(); return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr const& cash) { - os << cash->getValue() << " " << cash->getCurrency(); +std::ostream &operator<<(std::ostream &os, Cash cash) { + os << cash.getValue() << " " << cash.getCurrency(); return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr const& money) { - os << money->getValue() << " " << money->getCurrency(); +std::ostream &operator<<(std::ostream &os, Money money) { + os << money.getValue() << " " << money.getCurrency(); return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr const& person) { +std::ostream &operator<<(std::ostream &os, Person *person) { os << person->getName(); return os; } -std::ostream &operator<<(std::ostream &os, BankAccount* bankAccount) { - os << bankAccount->getName() << " " << ": " << bankAccount->getMoney(); +std::ostream &operator<<(std::ostream &os, BankAccount bankAccount) { + os << bankAccount.getOwner() << " " << bankAccount.getName() << ": " << bankAccount.getMoney(); return os; } -std::set> banks; -std::set> owners; -CashFactory *cashFactory; +std::set banks; void setup() { - //FIXME: das hier könnte das Problem sein - // http://www.cplusplus.com/forum/beginner/74320/ - // Fehler könnte so gefunden werden: - // https://stackoverflow.com/a/6685693 - - std::shared_ptr bank1 = std::make_shared(new Bank("Bank 1")); - std::shared_ptr bank2 = std::make_shared(new Bank("Bank 2")); - std::shared_ptr bank3 = std::make_shared(new Bank("Bank 3")); - - std::shared_ptr max = std::make_shared(new Person("Max Müller")); - std::shared_ptr marius = std::make_shared(new Person("Marius Müller")); - std::shared_ptr alex = std::make_shared(new Person("Alex Maier")); - - owners.insert(max); - owners.insert(marius); - owners.insert(alex); - bank1->addAccount(std::make_shared(new BankAccount(max, "Konto 1"))); - bank2->addAccount(std::make_shared(new BankAccount(max, "Konto 2"))); - bank3->addAccount(std::make_shared(new BankAccount(alex, "privat"))); - bank1->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 1"))); - bank2->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 2"))); - bank3->addAccount(std::make_shared(new BankAccount(alex, "geschäftlich 3"))); - bank1->addAccount(std::make_shared(new BankAccount(marius, "Konto 1"))); - bank2->addAccount(std::make_shared(new BankAccount(marius, "Konto 2"))); - bank3->addAccount(std::make_shared(new BankAccount(marius, "Konto 3"))); + Bank *bank1 = new Bank("Bank 1"); + Bank *bank2 = new Bank("Bank 2"); + Bank *bank3 = new Bank("Bank 3"); - banks.insert(std::move(bank1)); - banks.insert(std::move(bank2)); - banks.insert(std::move(bank3)); + Person *max = new Person("Max Müller"); + Person *marius = new Person("Marius Müller"); + Person *alex = new Person("Alex Maier"); - cashFactory = new CashFactory(); + + 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(bank1); + banks.insert(bank2); + banks.insert(bank3); } void simulate() { - for(auto && bank : banks) { + auto *cashFactory = new CashFactory(); + + for (Bank *bank : banks) { std::cout << std::endl; std::cout << "======================== " << bank->getName() << " ========================" << std::endl; std::cout << std::endl; - for(auto && bankAccount : bank->getAccounts()) { + for (BankAccount *bankAccount : bank->getAccounts()) { for (int i = 0; i < 10000; ++i) { int rnd = distribution(generator); - std::cout << rnd << std::endl; - std::shared_ptr bill = cashFactory->printBill(rnd, CurrencyValue::USD); - std::shared_ptr coin = cashFactory->printCoin(rnd, CurrencyValue::USD); + Bill *bill = cashFactory->printBill(rnd, CurrencyValue::USD); + Coin *coin = cashFactory->printCoin(rnd, CurrencyValue::USD); if (bill != nullptr) { - bankAccount->operator+(bill); + *bankAccount + bill; } if (coin != nullptr) { - //bankAccount->operator+(coin); + *bankAccount + coin; } - //std::shared_ptr fee = bankAccount->operator-(10); + + Money *fee = *bankAccount - 10; } - std::cout << "Test2" << std::endl; - std::cout << bankAccount.get() << std::endl; + std::cout << *bankAccount << std::endl; } } - } void tearDown() { - + for (Bank *bank : banks) { + for (BankAccount *bankAccount : bank->getAccounts()) { + delete(bankAccount); + } + delete(bank); + } }