diff --git a/.gitignore b/.gitignore index a43073e..3dbd1ee 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ doc/ googletest-build googletest-download googletest-src +lib diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b25686..e90e94f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ if(DOXYGEN_FOUND) ) endif(DOXYGEN_FOUND) +#[[ # Download and unpack googletest at configure time configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . @@ -55,6 +56,7 @@ endif() #add_executable(example example.cpp) #target_link_libraries(example gtest_main) #add_test(NAME example_test COMMAND example) +]] add_subdirectory(src) diff --git a/Doxyfile b/Doxyfile index 0ba75e8..1ee1ca7 100644 --- a/Doxyfile +++ b/Doxyfile @@ -3,7 +3,7 @@ #--------------------------------------------------------------------------- PROJECT_NAME = C/C++ PROJECT_NUMBER = -OUTPUT_DIRECTORY = @CMAKE_CURRENT_SOURCE_DIR@/doc +OUTPUT_DIRECTORY = /home/joethei/workspaces/C_CPP/doc CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = Englisch ... @@ -17,7 +17,7 @@ EXTRACT_ALL = NO #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ +INPUT = /home/joethei/workspaces/C_CPP/src/ FILE_PATTERNS = RECURSIVE = YES EXCLUDE = diff --git a/src/07_STD/CMakeLists.txt b/src/07_STD/CMakeLists.txt index 659f9c3..107e994 100644 --- a/src/07_STD/CMakeLists.txt +++ b/src/07_STD/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(07_STD_MP MP/grundgeruest.cpp MP/BinaryOctet.cpp MP/BinaryOctet.h) add_executable(07_STD_Testat Testat/grundgeruest.cpp Testat/BinaryOctet.h Testat/BinaryOctet.cpp) -target_link_libraries(07_STD_Testat gtest_main) -add_test(NAME 07_STD_Testat COMMAND InsertBinaryOctet) \ No newline at end of file +#target_link_libraries(07_STD_Testat gtest_main) +#add_test(NAME 07_STD_Testat COMMAND InsertBinaryOctet) \ No newline at end of file diff --git a/src/08_PTRN/CMakeLists.txt b/src/08_PTRN/CMakeLists.txt index 91e5740..ecc59ef 100644 --- a/src/08_PTRN/CMakeLists.txt +++ b/src/08_PTRN/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(08_PTRN_MP MP/VehicleFactory.cpp MP/VehicleFactory.hpp MP/Vehicle.cpp MP/Vehicle.hpp MP/Car.cpp MP/Car.hpp MP/Truck.cpp MP/Truck.hpp MP/Logger.cpp MP/Logger.hpp MP/main.cpp) -add_executable(08_PTRN_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h Testat/Logger.cpp Testat/Logger.hpp Testat/Currency.h Testat/BankAccount.cpp Testat/BankAccount.h Testat/Cash.cpp Testat/Cash.h Testat/Currency.cpp) \ No newline at end of file +add_executable(08_PTRN_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h Testat/Logger.cpp Testat/Logger.hpp Testat/Currency.h Testat/BankAccount.cpp Testat/BankAccount.h Testat/Cash.cpp Testat/Cash.h Testat/Currency.cpp Testat/Coin.cpp Testat/Coin.h Testat/Bill.cpp Testat/Bill.h Testat/CashFactory.cpp Testat/CashFactory.h) \ No newline at end of file diff --git a/src/08_PTRN/Testat/BankAccount.cpp b/src/08_PTRN/Testat/BankAccount.cpp index 48d4705..9b5d1f2 100644 --- a/src/08_PTRN/Testat/BankAccount.cpp +++ b/src/08_PTRN/Testat/BankAccount.cpp @@ -2,8 +2,9 @@ BankAccount::BankAccount(std::string name) : name(std::move(name)) {} -void BankAccount::add(Cash cash) { - money = Money(money.getValue() + cash.getValue(), cash.getCurrency()); +Money* BankAccount::operator+(Money* money) { + Money *result = new Money(money->getValue() + getMoney().getValue()); + return result; } bool BankAccount::operator<(BankAccount bankAccount) { diff --git a/src/08_PTRN/Testat/BankAccount.h b/src/08_PTRN/Testat/BankAccount.h index e1f288e..3d8998e 100644 --- a/src/08_PTRN/Testat/BankAccount.h +++ b/src/08_PTRN/Testat/BankAccount.h @@ -12,7 +12,7 @@ private: Money money; public: explicit BankAccount(std::string name); - void add(Cash cash); + Money* operator+(Money* money); bool operator<(BankAccount bankAccount); std::string getName(); Money getMoney(); diff --git a/src/08_PTRN/Testat/Bill.cpp b/src/08_PTRN/Testat/Bill.cpp new file mode 100644 index 0000000..2cf6295 --- /dev/null +++ b/src/08_PTRN/Testat/Bill.cpp @@ -0,0 +1,11 @@ +#include + +#include "Bill.h" + +Bill::Bill(int value, Currency currency, std::string serial) : Cash(value, currency), serial(std::move(serial)){ + +} + +std::string Bill::getSerial() { + return serial; +} diff --git a/src/08_PTRN/Testat/Bill.h b/src/08_PTRN/Testat/Bill.h new file mode 100644 index 0000000..71feaf5 --- /dev/null +++ b/src/08_PTRN/Testat/Bill.h @@ -0,0 +1,16 @@ +#ifndef C_C_BILL_H +#define C_C_BILL_H + + +#include "Cash.h" + +class Bill : public Cash{ +private: + std::string serial; +public: + Bill(int value, Currency currency, std::string serial); + std::string getSerial(); +}; + + +#endif diff --git a/src/08_PTRN/Testat/Cash.cpp b/src/08_PTRN/Testat/Cash.cpp index 22ebf06..94a65b6 100644 --- a/src/08_PTRN/Testat/Cash.cpp +++ b/src/08_PTRN/Testat/Cash.cpp @@ -4,10 +4,6 @@ #include "Cash.h" -Cash::Cash(double value, Currency currency, std::string serial) : Money(value, currency), serial(std::move(serial)) { +Cash::Cash(int value, Currency currency) : Money(value, currency) { -} - -std::string Cash::getSerial() { - return serial; -} +} \ No newline at end of file diff --git a/src/08_PTRN/Testat/Cash.h b/src/08_PTRN/Testat/Cash.h index f1bdaf4..24c8525 100644 --- a/src/08_PTRN/Testat/Cash.h +++ b/src/08_PTRN/Testat/Cash.h @@ -1,21 +1,13 @@ -// -// Created by JThei on 02.12.2018. -// - #ifndef C_C_CASH_H #define C_C_CASH_H - #include #include "Money.h" class Cash : public Money{ private: - std::string serial; public: - Cash(double value, Currency currency, std::string serial); - std::string getSerial(); + Cash(int value, Currency currency); }; - -#endif //C_C_CASH_H +#endif diff --git a/src/08_PTRN/Testat/CashFactory.cpp b/src/08_PTRN/Testat/CashFactory.cpp new file mode 100644 index 0000000..cab4fbe --- /dev/null +++ b/src/08_PTRN/Testat/CashFactory.cpp @@ -0,0 +1 @@ +#include "CashFactory.h" diff --git a/src/08_PTRN/Testat/CashFactory.h b/src/08_PTRN/Testat/CashFactory.h new file mode 100644 index 0000000..d2764e9 --- /dev/null +++ b/src/08_PTRN/Testat/CashFactory.h @@ -0,0 +1,9 @@ +#ifndef C_C_CASHFACTORY_H +#define C_C_CASHFACTORY_H + +class CashFactory { + +}; + + +#endif diff --git a/src/08_PTRN/Testat/Coin.cpp b/src/08_PTRN/Testat/Coin.cpp new file mode 100644 index 0000000..5908b61 --- /dev/null +++ b/src/08_PTRN/Testat/Coin.cpp @@ -0,0 +1,5 @@ +#include "Coin.h" + +Coin::Coin(int value, Currency currency) : Cash(value, currency) { + +} diff --git a/src/08_PTRN/Testat/Coin.h b/src/08_PTRN/Testat/Coin.h new file mode 100644 index 0000000..b700dec --- /dev/null +++ b/src/08_PTRN/Testat/Coin.h @@ -0,0 +1,14 @@ +#ifndef C_C_COIN_H +#define C_C_COIN_H + + +#include "Cash.h" + +class Coin : public Cash{ +private: +public: + Coin(int value, Currency currency); +}; + + +#endif diff --git a/src/08_PTRN/Testat/Money.cpp b/src/08_PTRN/Testat/Money.cpp index b4c3fd4..3ceba89 100644 --- a/src/08_PTRN/Testat/Money.cpp +++ b/src/08_PTRN/Testat/Money.cpp @@ -1,6 +1,6 @@ #include "Money.h" -Money::Money(double value, Currency currency) : value(value), currency(currency) { +Money::Money(int value, Currency currency) : value(value), currency(currency) { } @@ -10,6 +10,12 @@ Money& Money::operator=(Money money) { return *this; } +Money &Money::operator=(Money *money) { + value = money->getValue(); + currency = money->getCurrency(); + return *this; +} + Money Money::operator+(Money &a) { if(currency == a.currency) { return Money(); @@ -40,6 +46,6 @@ Currency Money::getCurrency() { return currency; } -double Money::getValue() { +int Money::getValue() { return value; } diff --git a/src/08_PTRN/Testat/Money.h b/src/08_PTRN/Testat/Money.h index b0facb3..3b95672 100644 --- a/src/08_PTRN/Testat/Money.h +++ b/src/08_PTRN/Testat/Money.h @@ -1,16 +1,16 @@ #ifndef C_C_MONEY_H #define C_C_MONEY_H - #include "Currency.h" class Money { private: - double value; + int value; Currency currency; public: - explicit Money(double value = 0, Currency currency = CurrencyValue::USD); + explicit Money(int value = 0, Currency currency = CurrencyValue::USD); Money& operator=(Money money); + Money& operator=(Money * money); Money operator+(Money &a); Money operator-(Money &a); const Money operator++(int); @@ -18,9 +18,8 @@ public: bool operator==(Money &a); bool operator!=(Money &a); - double getValue(); + int getValue(); Currency getCurrency(); }; - #endif diff --git a/src/08_PTRN/Testat/main.cpp b/src/08_PTRN/Testat/main.cpp index 05e3afa..46f4296 100644 --- a/src/08_PTRN/Testat/main.cpp +++ b/src/08_PTRN/Testat/main.cpp @@ -5,9 +5,10 @@ #include #include "Currency.h" #include "BankAccount.h" +#include "Bill.h" std::default_random_engine generator; -std::uniform_real_distribution distribution(-100, 500); +std::uniform_int_distribution distribution(-100, 500); std::string random_string(size_t length) { auto randchar = []() -> char { @@ -35,8 +36,13 @@ std::ostream &operator<<(std::ostream &os, Currency currency) { return os; } +std::ostream &operator<<(std::ostream &os, Bill bill) { + os << bill.getValue() << " " << bill.getCurrency() << bill.getSerial(); + return os; +} + std::ostream &operator<<(std::ostream &os, Cash cash) { - os << cash.getValue() << " " << cash.getCurrency() << ": " << cash.getSerial(); + os << cash.getValue() << " " << cash.getCurrency(); return os; } @@ -50,8 +56,8 @@ std::ostream &operator<<(std::ostream &os, BankAccount bankAccount) { return os; } -Cash cashPrinter(double value, Currency currency) { - return Cash(value, currency, random_string(5)); +Bill billPrinter(int value, Currency currency) { + return Bill(value, currency, random_string(5)); } @@ -63,12 +69,11 @@ int main(int argc, char **argv) { accounts.insert(new BankAccount("Marius")); accounts.insert(new BankAccount("Test")); - std::for_each(accounts.begin(), accounts.end(), [] (BankAccount* bankAccount){ - double rnd = distribution(generator); - Cash cash = cashPrinter(rnd, CurrencyValue::USD); - std::cout << cash << std::endl; - bankAccount->add(cash); - std::cout << *bankAccount << std::endl; + int rnd = distribution(generator); + Bill bill = billPrinter(rnd, CurrencyValue::USD); + std::cout << bill << std::endl; + //Money* res = bankAccount + &bill; + //std::cout << *res << std::endl; }); } \ No newline at end of file