10_PITF: Fehler behoben, wie auch immer
This commit is contained in:
parent
9b5e4fb7bf
commit
8815c87f86
|
@ -1,9 +1,14 @@
|
|||
#include <utility>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
|
||||
#include "Bank.h"
|
||||
|
||||
std::default_random_engine gen(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> dist(0, 9000);
|
||||
|
||||
Bank::Bank(std::string name) : name(std::move(name)) {}
|
||||
|
||||
Bank::Bank(Bank *bank) : name(std::move(bank->getName())) {}
|
||||
|
@ -13,6 +18,12 @@ void Bank::addAccount(BankAccount * account) {
|
|||
}
|
||||
|
||||
void Bank::moveMoney(std::shared_ptr<Bank> bank, int amount) {
|
||||
//ab und zu etwas Geld verlieren
|
||||
int chance = dist(gen);
|
||||
int value = dist(gen);
|
||||
if(chance == 42 && amount >= value) {
|
||||
amount -=value;
|
||||
}
|
||||
money -= amount;
|
||||
bank->money -= amount;
|
||||
}
|
||||
|
|
|
@ -3,30 +3,34 @@
|
|||
#include <utility>
|
||||
#include <random>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
#include "BankAccount.h"
|
||||
#include "CashFactory.h"
|
||||
|
||||
|
||||
std::default_random_engine gen(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> dist(0, 9000);
|
||||
std::default_random_engine gen2(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> dist2(0, 9000);
|
||||
|
||||
BankAccount::BankAccount(std::shared_ptr<Person> owner, std::string name) : name(std::move(name)) {
|
||||
owner = std::move(owner);
|
||||
this->owner = std::move(owner);
|
||||
money = std::make_shared<Money>(new Money(0, CurrencyValue::USD));
|
||||
}
|
||||
|
||||
BankAccount::BankAccount(BankAccount *bankAccount) : name(std::move(bankAccount->getName())) {
|
||||
owner = std::move(bankAccount->getOwner());
|
||||
this->owner = std::move(bankAccount->getOwner());
|
||||
money = std::make_shared<Money>(new Money(0, CurrencyValue::USD));
|
||||
}
|
||||
|
||||
BankAccount *BankAccount::operator+(Money *money) {
|
||||
|
||||
BankAccount *BankAccount::operator+(Money * money) {
|
||||
|
||||
//ab und zu Geld verlieren
|
||||
int rnd = dist(gen);
|
||||
int rnd = dist2(gen2);
|
||||
if(rnd == 42) {
|
||||
return this;
|
||||
}
|
||||
BankAccount::money = std::make_shared<Money>(new Money(money->getValue() + getMoney()->getValue()));
|
||||
|
||||
this->money = std::make_shared<Money>(new Money(this->money->getValue() + money->getValue(), CurrencyValue::USD));
|
||||
|
||||
|
||||
return this;
|
||||
|
@ -38,10 +42,6 @@ Money *BankAccount::operator-(int value) {
|
|||
return cashFactory->printCoin(value, CurrencyValue::USD).get();
|
||||
}
|
||||
|
||||
bool BankAccount::operator<(BankAccount *bankAccount) {
|
||||
return money->getValue() < bankAccount->money->getValue();
|
||||
}
|
||||
|
||||
std::string BankAccount::getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ public:
|
|||
explicit BankAccount(BankAccount* bankAccount);
|
||||
BankAccount* operator+(Money * money);
|
||||
Money* operator-(int value);
|
||||
bool operator<(BankAccount * bankAccount);
|
||||
std::string getName();
|
||||
std::shared_ptr<Person> getOwner();
|
||||
std::shared_ptr<Money> getMoney();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <iostream>
|
||||
#include "Money.h"
|
||||
|
||||
Money::Money(int value, Currency currency) : value(value), currency(currency) {}
|
||||
|
|
|
@ -33,8 +33,8 @@ std::ostream &operator<<(std::ostream &os, Cash cash) {
|
|||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Money money) {
|
||||
os << money.getValue() << " " << money.getCurrency();
|
||||
std::ostream &operator<<(std::ostream &os, Money * money) {
|
||||
os << money->getValue() << " " << money->getCurrency();
|
||||
return os;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,10 @@ std::ostream &operator<<(std::ostream &os, BankAccount* bankAccount) {
|
|||
return os;
|
||||
}
|
||||
|
||||
bool sortMoney(std::shared_ptr<Money> const &a, std::shared_ptr<Money> const &b) {
|
||||
return a->getValue() < b->getValue();
|
||||
}
|
||||
|
||||
std::set<std::shared_ptr<Bank>> banks;
|
||||
std::vector<std::shared_ptr<Money>> moneyVector;
|
||||
void setup() {
|
||||
|
@ -89,23 +93,17 @@ void simulate() {
|
|||
std::shared_ptr<Bill> bill = cashFactory->printBill(rnd, CurrencyValue::USD);
|
||||
std::shared_ptr<Coin> coin = cashFactory->printCoin(rnd, CurrencyValue::USD);
|
||||
if (bill != nullptr) {
|
||||
//*bankAccount + bill.get();
|
||||
*bankAccount + bill.get();
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Bill>(bill));
|
||||
}
|
||||
if (coin != nullptr) {
|
||||
//*bankAccount + coin.get();
|
||||
*bankAccount + coin.get();
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Coin>(coin));
|
||||
}
|
||||
|
||||
Money *fee = *bankAccount - 10;
|
||||
delete fee;
|
||||
}
|
||||
std::cout << bankAccount->getName() << ": ";
|
||||
/*
|
||||
* FIXME: Das hier mag er nicht
|
||||
* std::cout << bankAccount->getMoney()->getValue() << " ";
|
||||
* std::cout << bankAccount->getMoney()->getCurrency().getValue() << std::endl;
|
||||
*/
|
||||
std::cout << bankAccount << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +118,7 @@ void simulate() {
|
|||
}
|
||||
}
|
||||
|
||||
std::sort(moneyVector.begin(), moneyVector.end());
|
||||
std::sort(moneyVector.begin(), moneyVector.end(), sortMoney);
|
||||
|
||||
for(auto && money : moneyVector) {
|
||||
std::cout << money->getValue() << ", ";
|
||||
|
@ -130,20 +128,12 @@ void simulate() {
|
|||
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
for(auto && bank : banks) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::cout << "+++++++++++++++++++++++++ " << "setup()" << " +++++++++++++++++++++++++" << std::endl;
|
||||
setup();
|
||||
std::cout << "+++++++++++++++++++++++++ " << "simulate()" << " +++++++++++++++++++++++++" << std::endl;
|
||||
simulate();
|
||||
std::cout << "+++++++++++++++++++++++++ " << "tearDown()" << " +++++++++++++++++++++++++" << std::endl;
|
||||
tearDown();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -7,13 +7,4 @@ add_subdirectory(06_POLY)
|
|||
add_subdirectory(07_STD)
|
||||
add_subdirectory(08_PTRN)
|
||||
add_subdirectory(10_PITF)
|
||||
|
||||
add_subdirectory(11_PUTT)
|
||||
|
||||
#add_executable(SequenceDiagram 11_PUTT/05_OO_b/SequenceDiagramCreator.cpp 11_PUTT/05_OO_b/main.cpp)
|
||||
|
||||
#add_executable(LCDDisplay 11_PUTT/02_Ment/LCDDisplay.cpp)
|
||||
|
||||
#add_executable(CopyOnWrite 11_PUTT/CopyOnWrite/OneByOneMatrix.cpp 11_PUTT/CopyOnWrite/LargeCowMatrix.cpp 11_PUTT/CopyOnWrite/main.cpp)
|
||||
|
||||
#add_executable(Banking 10_PITF/MP/banking_base_rawptr.cpp)
|
||||
add_subdirectory(11_PUTT)
|
Loading…
Reference in New Issue