10_PITF: einen Fehler behoben, neuen erhalten
This commit is contained in:
parent
3dd56c45a9
commit
dd71612348
@ -21,10 +21,8 @@ BankAccount::BankAccount(BankAccount &bankAccount) : name(bankAccount.name) {
|
||||
}
|
||||
|
||||
std::shared_ptr<BankAccount> BankAccount::operator+(std::shared_ptr<Bill> money) {
|
||||
std::shared_ptr<Money> ptr = std::make_shared<Money>(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<BankAccount>(*this);
|
||||
}
|
||||
@ -37,12 +35,13 @@ std::shared_ptr<BankAccount> BankAccount::operator+(std::shared_ptr<Coin> money)
|
||||
return std::make_shared<BankAccount>(*this);
|
||||
}
|
||||
|
||||
std::shared_ptr<Money> BankAccount::operator-(int value) {
|
||||
std::shared_ptr<Coin> BankAccount::operator-(int value) {
|
||||
auto * cashFactory = new CashFactory();
|
||||
|
||||
return cashFactory->printCoin(value, CurrencyValue::USD);
|
||||
}
|
||||
|
||||
|
||||
bool BankAccount::operator<(std::shared_ptr<BankAccount> bankAccount) {
|
||||
return this->money->getValue() < bankAccount->money->getValue();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
BankAccount(BankAccount& bankAccount);
|
||||
std::shared_ptr<BankAccount> operator+(std::shared_ptr<Coin> money);
|
||||
std::shared_ptr<BankAccount> operator+(std::shared_ptr<Bill> money);
|
||||
std::shared_ptr<Money> operator-(int value);
|
||||
std::shared_ptr<Coin> operator-(int value);
|
||||
bool operator<(std::shared_ptr<BankAccount> bankAccount);
|
||||
std::string getName();
|
||||
std::shared_ptr<Person> getOwner();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef C_C_CASH_H
|
||||
#define C_C_CASH_H
|
||||
|
||||
#include <string>
|
||||
#include "Money.h"
|
||||
#include "HeapObject.h"
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ private:
|
||||
public:
|
||||
Coin(int value, Currency currency);
|
||||
explicit Coin(Coin *coin);
|
||||
int getValue() override;
|
||||
Currency getCurrency();
|
||||
int getValue();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -20,6 +20,18 @@ std::shared_ptr<Money> Money::operator+(Money &a) {
|
||||
}else return std::make_shared<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
std::shared_ptr<Money> Money::operator+(Bill &a) {
|
||||
if(currency == a.getCurrency()) {
|
||||
return std::make_shared<Money>(Money(value + a.getValue(), CurrencyValue::USD));
|
||||
}else return std::make_shared<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
std::shared_ptr<Money> Money::operator+(Coin &a) {
|
||||
if(currency == a.getCurrency()) {
|
||||
return std::make_shared<Money>(Money(value + a.getValue(), CurrencyValue::USD));
|
||||
}else return std::make_shared<Money>(Money(-1, Currency(CurrencyValue::USD)));
|
||||
}
|
||||
|
||||
std::shared_ptr<Money> Money::operator-(Money &a) {
|
||||
if(currency == a.currency) {
|
||||
return std::make_unique<Money>(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;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Currency.h"
|
||||
#include "Bill.h"
|
||||
#include "Coin.h"
|
||||
|
||||
class Money {
|
||||
private:
|
||||
@ -14,12 +16,15 @@ public:
|
||||
explicit Money(Money* money);
|
||||
std::shared_ptr<Money> operator=(Money money);
|
||||
std::shared_ptr<Money> operator+(Money &a);
|
||||
std::shared_ptr<Money> operator+(Bill &a);
|
||||
std::shared_ptr<Money> operator+(Coin &a);
|
||||
std::shared_ptr<Money> operator-(Money &a);
|
||||
const std::shared_ptr<Money> operator++(int);
|
||||
const std::shared_ptr<Money> operator--(int);
|
||||
|
||||
virtual int getValue();
|
||||
Currency getCurrency();
|
||||
virtual void setValue(int value);
|
||||
virtual Currency getCurrency();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@ std::ostream &operator<<(std::ostream &os, std::shared_ptr<Bill> const& bill) {
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, std::shared_ptr<Cash> const& cash) {
|
||||
std::ostream &operator<<(std::ostream &os, std::shared_ptr<Coin> 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<Bank> bank1 = std::make_shared<Bank>(new Bank("Bank 1"));
|
||||
std::shared_ptr<Bank> bank2 = std::make_shared<Bank>(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<Money> fee = bankAccount->operator-(10);
|
||||
//std::shared_ptr<Money> fee = bankAccount->operator-(10);
|
||||
}
|
||||
std::cout << "Test2" << std::endl;
|
||||
std::cout << bankAccount.get() << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user