10_PITF: Namespaces hinzugefügt

This commit is contained in:
Johannes Theiner 2019-01-06 11:29:33 +01:00
parent a2c74528cd
commit 964a00f596
22 changed files with 229 additions and 107 deletions

View File

@ -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">
[Dokumentation](https://files.joethei.space/documentation/Studium/C_CPP/)

View File

@ -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);
@ -36,3 +38,4 @@ std::string Bank::getName() {
return name;
}

View File

@ -4,6 +4,13 @@
#include "BankAccount.h"
#include "HeapObject.h"
namespace banking {
/**
* @author Johannes Theiner<kontakt@joethei.xyz>
* @version 1.0
*/
class Bank : public HeapObject {
private:
std::string name;
@ -11,11 +18,18 @@ private:
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

View File

@ -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);

View File

@ -7,6 +7,12 @@
#include "Money.h"
#include "Person.h"
namespace banking {
/**
* @author Johannes Theiner<kontakt@joethei.xyz>
* @version 1.0
*/
class BankAccount {
private:
std::string name;
@ -14,12 +20,20 @@ private:
std::shared_ptr<Money> money;
public:
explicit BankAccount(std::shared_ptr<Person> owner, std::string name);
explicit BankAccount(BankAccount *bankAccount);
BankAccount* operator+(Money * money);
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

View File

@ -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)){
}

View File

@ -4,6 +4,12 @@
#include "Cash.h"
namespace banking {
/**
* @author Johannes Theiner<kontakt@joethei.xyz>
* @version 1.0
*/
class Bill : public Cash{
private:
std::string serial;
@ -11,8 +17,11 @@ public:
explicit Bill(int value, Currency currency, std::string serial);
explicit Bill(Bill *bill);
std::string getSerial();
int getValue();
int getValue() override;
};
}
#endif

View File

@ -3,4 +3,6 @@
#include "Cash.h"
using namespace banking;
Cash::Cash(int value, Currency currency) : Money(value, currency) {}

View File

@ -5,10 +5,19 @@
#include "Money.h"
#include "HeapObject.h"
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

View File

@ -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};

View File

@ -7,6 +7,12 @@
#include "Bill.h"
#include "Coin.h"
namespace banking {
/**
* @author Johannes Theiner<kontakt@joethei.xyz
* @version 1.0
*/
class CashFactory {
private:
std::string randomString(size_t length);
@ -14,5 +20,7 @@ public:
std::shared_ptr<Bill> printBill(int value, Currency currency);
std::shared_ptr<Coin> printCoin(int value, Currency currency);
};
}
#endif

View File

@ -1,5 +1,7 @@
#include "Coin.h"
using namespace banking;
Coin::Coin(int value, Currency currency) : Cash(value, currency) {
}

View File

@ -4,6 +4,12 @@
#include "Cash.h"
namespace banking {
/**
* @author Johannes Theiner<kontakt@joethei.xyz>
* @version 1.0
*/
class Coin : public Cash{
private:
public:
@ -11,5 +17,8 @@ public:
explicit Coin(Coin *coin);
int getValue() override;
};
}
#endif

View File

@ -1,6 +1,8 @@
#include <string>
#include "Currency.h"
using namespace banking;
Currency::Currency(CurrencyValue value) : value(value) {
}

View File

@ -3,12 +3,19 @@
#include <vector>
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;
@ -19,5 +26,8 @@ public:
CurrencyValue getValue();
};
}
#endif

View File

@ -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;
}

View File

@ -3,6 +3,10 @@
#include <cstdlib>
/**
* @author Carsten Link
* @version 1.0
*/
class HeapObject {
public:
void *operator new(size_t size);

View File

@ -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()) {}

View File

@ -3,23 +3,40 @@
#include "Currency.h"
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();
};
}
#endif

View File

@ -2,6 +2,8 @@
#include "Person.h"
using namespace banking;
Person::Person(std::string name) : name(std::move(name)){
}

View File

@ -6,15 +6,24 @@
#include <memory>
#include "Money.h"
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

View File

@ -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;