10_PITF: Namespaces hinzugefügt
This commit is contained in:
parent
a2c74528cd
commit
964a00f596
|
@ -1 +1,3 @@
|
|||
<img src="https://teamcity.joethei.xyz/app/rest/builds/aggregated/strob:(branch:(buildType:(id:Studium_Programmierung_CC),policy:active_history_and_active_vcs_branches),locator:(buildType:(id:Studium_Programmierung_CC)))/statusIcon.svg">
|
||||
<img src="https://teamcity.joethei.xyz/app/rest/builds/aggregated/strob:(branch:(buildType:(id:Studium_Programmierung_CC),policy:active_history_and_active_vcs_branches),locator:(buildType:(id:Studium_Programmierung_CC)))/statusIcon.svg">
|
||||
|
||||
[Dokumentation](https://files.joethei.space/documentation/Studium/C_CPP/)
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "Bank.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
std::default_random_engine gen(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> dist(0, 9000);
|
||||
|
||||
|
@ -13,7 +15,7 @@ Bank::Bank(std::string name) : name(std::move(name)) {}
|
|||
|
||||
Bank::Bank(Bank *bank) : name(std::move(bank->getName())) {}
|
||||
|
||||
void Bank::addAccount(BankAccount * account) {
|
||||
void Bank::addAccount(BankAccount *account) {
|
||||
accounts.insert(std::move(std::make_unique<BankAccount>(account)));
|
||||
}
|
||||
|
||||
|
@ -21,8 +23,8 @@ 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;
|
||||
if (chance == 42 && amount >= value) {
|
||||
amount -= value;
|
||||
}
|
||||
money -= amount;
|
||||
bank->money -= amount;
|
||||
|
@ -36,3 +38,4 @@ std::string Bank::getName() {
|
|||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,18 +4,32 @@
|
|||
#include "BankAccount.h"
|
||||
#include "HeapObject.h"
|
||||
|
||||
class Bank : public HeapObject{
|
||||
private:
|
||||
std::string name;
|
||||
std::set<std::shared_ptr<BankAccount>> accounts;
|
||||
int money;
|
||||
public:
|
||||
explicit Bank(std::string name);
|
||||
explicit Bank(Bank* bank);
|
||||
void addAccount(BankAccount * account);
|
||||
void moveMoney(std::shared_ptr<Bank> bank, int amount);
|
||||
std::set<std::shared_ptr<BankAccount>> getAccounts();
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Bank : public HeapObject {
|
||||
private:
|
||||
std::string name;
|
||||
std::set<std::shared_ptr<BankAccount>> accounts;
|
||||
int money;
|
||||
public:
|
||||
explicit Bank(std::string name);
|
||||
|
||||
explicit Bank(Bank *bank);
|
||||
|
||||
void addAccount(BankAccount *account);
|
||||
|
||||
void moveMoney(std::shared_ptr<Bank> bank, int amount);
|
||||
|
||||
std::set<std::shared_ptr<BankAccount>> getAccounts();
|
||||
|
||||
std::string getName();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -8,6 +8,8 @@
|
|||
#include "BankAccount.h"
|
||||
#include "CashFactory.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
std::default_random_engine gen2(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> dist2(0, 9000);
|
||||
|
||||
|
@ -22,7 +24,7 @@ BankAccount::BankAccount(BankAccount *bankAccount) : name(std::move(bankAccount-
|
|||
}
|
||||
|
||||
|
||||
BankAccount *BankAccount::operator+(Money * money) {
|
||||
BankAccount *BankAccount::operator+(std::shared_ptr<Money> money) {
|
||||
|
||||
//ab und zu Geld verlieren
|
||||
int rnd = dist2(gen2);
|
||||
|
|
|
@ -7,19 +7,33 @@
|
|||
#include "Money.h"
|
||||
#include "Person.h"
|
||||
|
||||
class BankAccount {
|
||||
private:
|
||||
std::string name;
|
||||
std::shared_ptr<Person> owner;
|
||||
std::shared_ptr<Money> money;
|
||||
public:
|
||||
explicit BankAccount(std::shared_ptr<Person> owner, std::string name);
|
||||
explicit BankAccount(BankAccount* bankAccount);
|
||||
BankAccount* operator+(Money * money);
|
||||
Money* operator-(int value);
|
||||
std::string getName();
|
||||
std::shared_ptr<Person> getOwner();
|
||||
std::shared_ptr<Money> getMoney();
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class BankAccount {
|
||||
private:
|
||||
std::string name;
|
||||
std::shared_ptr<Person> owner;
|
||||
std::shared_ptr<Money> money;
|
||||
public:
|
||||
explicit BankAccount(std::shared_ptr<Person> owner, std::string name);
|
||||
|
||||
explicit BankAccount(BankAccount *bankAccount);
|
||||
|
||||
BankAccount *operator+(std::shared_ptr<Money> money);
|
||||
|
||||
Money *operator-(int value);
|
||||
|
||||
std::string getName();
|
||||
|
||||
std::shared_ptr<Person> getOwner();
|
||||
|
||||
std::shared_ptr<Money> getMoney();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Bill.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Bill::Bill(int value, Currency currency, std::string serial) : Cash(value, currency), serial(std::move(serial)){
|
||||
|
||||
}
|
||||
|
|
|
@ -4,15 +4,24 @@
|
|||
|
||||
#include "Cash.h"
|
||||
|
||||
class Bill : public Cash{
|
||||
private:
|
||||
std::string serial;
|
||||
public:
|
||||
explicit Bill(int value, Currency currency, std::string serial);
|
||||
explicit Bill(Bill *bill);
|
||||
std::string getSerial();
|
||||
int getValue();
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Bill : public Cash{
|
||||
private:
|
||||
std::string serial;
|
||||
public:
|
||||
explicit Bill(int value, Currency currency, std::string serial);
|
||||
explicit Bill(Bill *bill);
|
||||
std::string getSerial();
|
||||
int getValue() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -3,4 +3,6 @@
|
|||
|
||||
#include "Cash.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Cash::Cash(int value, Currency currency) : Money(value, currency) {}
|
|
@ -5,10 +5,19 @@
|
|||
#include "Money.h"
|
||||
#include "HeapObject.h"
|
||||
|
||||
class Cash : public Money, public HeapObject{
|
||||
private:
|
||||
public:
|
||||
Cash(int value, Currency currency);
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Cash : public Money, public HeapObject{
|
||||
private:
|
||||
public:
|
||||
Cash(int value, Currency currency);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <algorithm>
|
||||
#include "CashFactory.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
int allowedBills[5] = {100, 50, 20, 10, 5};
|
||||
int allowedCoins[8] = {1, 2, 5, 10, 20, 50, 100, 200};
|
||||
|
||||
|
|
|
@ -7,12 +7,20 @@
|
|||
#include "Bill.h"
|
||||
#include "Coin.h"
|
||||
|
||||
class CashFactory {
|
||||
private:
|
||||
std::string randomString(size_t length);
|
||||
public:
|
||||
std::shared_ptr<Bill> printBill(int value, Currency currency);
|
||||
std::shared_ptr<Coin> printCoin(int value, Currency currency);
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz
|
||||
* @version 1.0
|
||||
*/
|
||||
class CashFactory {
|
||||
private:
|
||||
std::string randomString(size_t length);
|
||||
public:
|
||||
std::shared_ptr<Bill> printBill(int value, Currency currency);
|
||||
std::shared_ptr<Coin> printCoin(int value, Currency currency);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -1,5 +1,7 @@
|
|||
#include "Coin.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Coin::Coin(int value, Currency currency) : Cash(value, currency) {
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,21 @@
|
|||
|
||||
#include "Cash.h"
|
||||
|
||||
class Coin : public Cash{
|
||||
private:
|
||||
public:
|
||||
explicit Coin(int value, Currency currency);
|
||||
explicit Coin(Coin *coin);
|
||||
int getValue() override;
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Coin : public Cash{
|
||||
private:
|
||||
public:
|
||||
explicit Coin(int value, Currency currency);
|
||||
explicit Coin(Coin *coin);
|
||||
int getValue() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <string>
|
||||
#include "Currency.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Currency::Currency(CurrencyValue value) : value(value) {
|
||||
}
|
||||
|
||||
|
|
|
@ -3,21 +3,31 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
enum class CurrencyValue {
|
||||
USD=100,
|
||||
EUR=80,
|
||||
GPD=75,
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
enum class CurrencyValue {
|
||||
USD=100,
|
||||
EUR=80,
|
||||
GPD=75,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Currency {
|
||||
private:
|
||||
CurrencyValue value;
|
||||
public:
|
||||
Currency(CurrencyValue value);
|
||||
bool operator==(Currency ¤cy);
|
||||
Currency& operator=(Currency currency);
|
||||
CurrencyValue getValue();
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
class Currency {
|
||||
private:
|
||||
CurrencyValue value;
|
||||
public:
|
||||
Currency(CurrencyValue value);
|
||||
bool operator==(Currency ¤cy);
|
||||
Currency& operator=(Currency currency);
|
||||
CurrencyValue getValue();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -12,9 +12,6 @@ void* HeapObject::operator new (size_t size){
|
|||
return new char[size];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HeapObject::HeapObject(){
|
||||
ctorCount++;
|
||||
}
|
||||
|
@ -24,8 +21,7 @@ HeapObject::~HeapObject(){
|
|||
}
|
||||
|
||||
bool HeapObject::assertionsHold(){
|
||||
//assert(ctorCount == newCount); // all objects have been allocated on heap
|
||||
std::cout << ctorCount << " : " << dtorCount << std::endl;
|
||||
assert(ctorCount == newCount); // all objects have been allocated on heap
|
||||
assert(ctorCount == dtorCount); // all objects have been deleted
|
||||
return true;
|
||||
}
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include <cstdlib>
|
||||
|
||||
/**
|
||||
* @author Carsten Link
|
||||
* @version 1.0
|
||||
*/
|
||||
class HeapObject {
|
||||
public:
|
||||
void *operator new(size_t size);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <iostream>
|
||||
#include "Money.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Money::Money(int value, Currency currency) : value(value), currency(currency) {}
|
||||
|
||||
Money::Money(Money *money) : value(money->getValue()), currency(money->getCurrency()) {}
|
||||
|
|
|
@ -3,23 +3,40 @@
|
|||
|
||||
#include "Currency.h"
|
||||
|
||||
class Money {
|
||||
private:
|
||||
int value;
|
||||
Currency currency;
|
||||
public:
|
||||
explicit Money(int value = 0, Currency currency = CurrencyValue::USD);
|
||||
explicit Money(Money *money);
|
||||
Money& operator=(Money money);
|
||||
Money& operator=(Money * money);
|
||||
Money operator+(Money &a);
|
||||
Money operator-(Money &a);
|
||||
const Money operator++(int);
|
||||
const Money operator--(int);
|
||||
bool operator<(Money &a);
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Money {
|
||||
private:
|
||||
int value;
|
||||
Currency currency;
|
||||
public:
|
||||
explicit Money(int value = 0, Currency currency = CurrencyValue::USD);
|
||||
|
||||
explicit Money(Money *money);
|
||||
|
||||
Money &operator=(Money money);
|
||||
|
||||
Money &operator=(Money *money);
|
||||
|
||||
Money operator+(Money &a);
|
||||
|
||||
Money operator-(Money &a);
|
||||
|
||||
const Money operator++(int);
|
||||
|
||||
const Money operator--(int);
|
||||
|
||||
bool operator<(Money &a);
|
||||
|
||||
virtual int getValue();
|
||||
|
||||
Currency getCurrency();
|
||||
};
|
||||
}
|
||||
|
||||
virtual int getValue();
|
||||
Currency getCurrency();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Person.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
Person::Person(std::string name) : name(std::move(name)){
|
||||
|
||||
}
|
||||
|
|
|
@ -6,15 +6,24 @@
|
|||
#include <memory>
|
||||
#include "Money.h"
|
||||
|
||||
class Person {
|
||||
private:
|
||||
std::string name;
|
||||
std::vector<std::shared_ptr<Money>> money;
|
||||
public:
|
||||
explicit Person(std::string name);
|
||||
explicit Person(Person* person);
|
||||
std::string getName();
|
||||
};
|
||||
namespace banking {
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner<kontakt@joethei.xyz>
|
||||
* @version 1.0
|
||||
*/
|
||||
class Person {
|
||||
private:
|
||||
std::string name;
|
||||
std::vector<std::shared_ptr<Money>> money;
|
||||
public:
|
||||
explicit Person(std::string name);
|
||||
|
||||
explicit Person(Person *person);
|
||||
|
||||
std::string getName();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "CashFactory.h"
|
||||
#include "Bank.h"
|
||||
|
||||
using namespace banking;
|
||||
|
||||
std::default_random_engine generator(static_cast<unsigned long>(time(nullptr)));
|
||||
std::uniform_int_distribution<int> distribution(-100, 500);
|
||||
|
||||
|
@ -93,11 +95,11 @@ 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;
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Bill>(bill));
|
||||
}
|
||||
if (coin != nullptr) {
|
||||
*bankAccount + coin.get();
|
||||
*bankAccount + coin;
|
||||
moneyVector.push_back(std::static_pointer_cast<Money, Coin>(coin));
|
||||
}
|
||||
Money *fee = *bankAccount - 10;
|
||||
|
|
Loading…
Reference in New Issue