08_PTRN: weitere Arbeit am Grundgerüst
This commit is contained in:
parent
534006088d
commit
7e43e93d8c
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,4 +14,5 @@ doc/
|
||||
googletest-build
|
||||
googletest-download
|
||||
googletest-src
|
||||
lib
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
4
Doxyfile
4
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 =
|
||||
|
@ -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)
|
||||
#target_link_libraries(07_STD_Testat gtest_main)
|
||||
#add_test(NAME 07_STD_Testat COMMAND InsertBinaryOctet)
|
@ -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)
|
||||
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)
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
11
src/08_PTRN/Testat/Bill.cpp
Normal file
11
src/08_PTRN/Testat/Bill.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include <utility>
|
||||
|
||||
#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;
|
||||
}
|
16
src/08_PTRN/Testat/Bill.h
Normal file
16
src/08_PTRN/Testat/Bill.h
Normal file
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,21 +1,13 @@
|
||||
//
|
||||
// Created by JThei on 02.12.2018.
|
||||
//
|
||||
|
||||
#ifndef C_C_CASH_H
|
||||
#define C_C_CASH_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#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
|
||||
|
1
src/08_PTRN/Testat/CashFactory.cpp
Normal file
1
src/08_PTRN/Testat/CashFactory.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "CashFactory.h"
|
9
src/08_PTRN/Testat/CashFactory.h
Normal file
9
src/08_PTRN/Testat/CashFactory.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef C_C_CASHFACTORY_H
|
||||
#define C_C_CASHFACTORY_H
|
||||
|
||||
class CashFactory {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
5
src/08_PTRN/Testat/Coin.cpp
Normal file
5
src/08_PTRN/Testat/Coin.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "Coin.h"
|
||||
|
||||
Coin::Coin(int value, Currency currency) : Cash(value, currency) {
|
||||
|
||||
}
|
14
src/08_PTRN/Testat/Coin.h
Normal file
14
src/08_PTRN/Testat/Coin.h
Normal file
@ -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
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -5,9 +5,10 @@
|
||||
#include <random>
|
||||
#include "Currency.h"
|
||||
#include "BankAccount.h"
|
||||
#include "Bill.h"
|
||||
|
||||
std::default_random_engine generator;
|
||||
std::uniform_real_distribution<double> distribution(-100, 500);
|
||||
std::uniform_int_distribution<int> 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;
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user