diff --git a/src/10_PITF/Testat/BankAccount.cpp b/src/10_PITF/Testat/BankAccount.cpp index ef311fb..c1a8ed7 100644 --- a/src/10_PITF/Testat/BankAccount.cpp +++ b/src/10_PITF/Testat/BankAccount.cpp @@ -21,10 +21,8 @@ BankAccount::BankAccount(BankAccount &bankAccount) : name(bankAccount.name) { } 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())); - std::cout << "Test" << std::endl; - BankAccount::money = ptr; + this->money->setValue(this->money->getValue() + money->getValue()); return std::make_shared(*this); } @@ -37,12 +35,13 @@ std::shared_ptr BankAccount::operator+(std::shared_ptr money) return std::make_shared(*this); } -std::shared_ptr BankAccount::operator-(int value) { +std::shared_ptr 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(); } diff --git a/src/10_PITF/Testat/BankAccount.h b/src/10_PITF/Testat/BankAccount.h index d5f5b5a..b7d887a 100644 --- a/src/10_PITF/Testat/BankAccount.h +++ b/src/10_PITF/Testat/BankAccount.h @@ -17,7 +17,7 @@ public: 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); + std::shared_ptr operator-(int value); bool operator<(std::shared_ptr bankAccount); std::string getName(); std::shared_ptr getOwner(); diff --git a/src/10_PITF/Testat/Bill.cpp b/src/10_PITF/Testat/Bill.cpp index 10fca77..c6d885f 100644 --- a/src/10_PITF/Testat/Bill.cpp +++ b/src/10_PITF/Testat/Bill.cpp @@ -10,6 +10,10 @@ Bill::Bill(Bill *bill) : Cash(bill->getValue(), bill->getCurrency()), serial(bil } +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 542888c..60a83e4 100644 --- a/src/10_PITF/Testat/Bill.h +++ b/src/10_PITF/Testat/Bill.h @@ -11,7 +11,8 @@ public: Bill(int value, Currency currency, std::string serial); explicit Bill(Bill *bill); std::string getSerial(); - int getValue() override; + Currency getCurrency(); + int getValue(); }; diff --git a/src/10_PITF/Testat/Cash.h b/src/10_PITF/Testat/Cash.h index cb4ddf5..7cc9587 100644 --- a/src/10_PITF/Testat/Cash.h +++ b/src/10_PITF/Testat/Cash.h @@ -1,7 +1,6 @@ #ifndef C_C_CASH_H #define C_C_CASH_H -#include #include "Money.h" #include "HeapObject.h" diff --git a/src/10_PITF/Testat/Coin.cpp b/src/10_PITF/Testat/Coin.cpp index 685fb87..50da068 100644 --- a/src/10_PITF/Testat/Coin.cpp +++ b/src/10_PITF/Testat/Coin.cpp @@ -8,6 +8,10 @@ Coin::Coin(Coin *coin) : Cash(coin->getValue(), coin->getCurrency()) { } +Currency Coin::getCurrency() { + return Money::getCurrency(); +} + int Coin::getValue() { return Money::getValue(); } diff --git a/src/10_PITF/Testat/Coin.h b/src/10_PITF/Testat/Coin.h index 65f71d1..5a61834 100644 --- a/src/10_PITF/Testat/Coin.h +++ b/src/10_PITF/Testat/Coin.h @@ -9,7 +9,8 @@ private: public: Coin(int value, Currency currency); explicit Coin(Coin *coin); - int getValue() override; + Currency getCurrency(); + int getValue(); }; #endif diff --git a/src/10_PITF/Testat/Money.cpp b/src/10_PITF/Testat/Money.cpp index 3ee0f38..0775bfd 100644 --- a/src/10_PITF/Testat/Money.cpp +++ b/src/10_PITF/Testat/Money.cpp @@ -20,6 +20,18 @@ std::shared_ptr Money::operator+(Money &a) { }else return std::make_shared(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) { if(currency == a.currency) { return std::make_unique(Money(value - a.value, CurrencyValue::USD)); @@ -40,6 +52,10 @@ int Money::getValue() { return value; } +void Money::setValue(int value) { + this->value = value; +} + Currency Money::getCurrency() { return currency; } diff --git a/src/10_PITF/Testat/Money.h b/src/10_PITF/Testat/Money.h index 39a0629..4d583e3 100644 --- a/src/10_PITF/Testat/Money.h +++ b/src/10_PITF/Testat/Money.h @@ -4,6 +4,8 @@ #include #include "Currency.h" +#include "Bill.h" +#include "Coin.h" class Money { private: @@ -14,12 +16,15 @@ public: 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); virtual int getValue(); - Currency getCurrency(); + virtual void setValue(int value); + virtual Currency getCurrency(); }; #endif diff --git a/src/10_PITF/Testat/main.cpp b/src/10_PITF/Testat/main.cpp index fb29f5b..2776586 100644 --- a/src/10_PITF/Testat/main.cpp +++ b/src/10_PITF/Testat/main.cpp @@ -29,7 +29,7 @@ std::ostream &operator<<(std::ostream &os, std::shared_ptr const& bill) { return os; } -std::ostream &operator<<(std::ostream &os, std::shared_ptr const& cash) { +std::ostream &operator<<(std::ostream &os, std::shared_ptr const& cash) { os << cash->getValue() << " " << cash->getCurrency(); return os; } @@ -56,6 +56,8 @@ CashFactory *cashFactory; 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")); @@ -102,9 +104,9 @@ void simulate() { bankAccount->operator+(bill); } if (coin != nullptr) { - bankAccount->operator+(coin); + //bankAccount->operator+(coin); } - std::shared_ptr fee = bankAccount->operator-(10); + //std::shared_ptr fee = bankAccount->operator-(10); } std::cout << "Test2" << std::endl; std::cout << bankAccount.get() << std::endl;