08_PTRN: nichts geändert...

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2018-12-18 09:30:06 +01:00
parent 35406afa44
commit 8944e7ad9a
3 changed files with 6 additions and 13 deletions

View File

@ -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/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 Testat/Person.cpp Testat/Person.h)
add_executable(08_PTRN_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h 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.h Testat/Person.cpp Testat/Person.h Testat/CashFactory.cpp)

View File

@ -1,9 +1,8 @@
#include <algorithm>
#include <iostream>
#include "CashFactory.h"
int allowedBills[5] = {100, 50, 20, 10, 5};
int allowedCoins[8] = {1, 2, 5, 10, 20, 50, 100, 200};
int allowedCoins[9] = {1, 2, 5, 10, 20, 50, 100, 200, 300};
Bill * CashFactory::printBill(int value, Currency currency) {
auto * iter = std::find(std::begin(allowedBills), std::end(allowedBills), value);
@ -11,10 +10,6 @@ Bill * CashFactory::printBill(int value, Currency currency) {
return nullptr;
}else {
std::string serial = randomString(15);
while(std::find(usedSerials.begin(), usedSerials.end(), serial) != usedSerials.end()) {
serial = randomString(15);
}
usedSerials.push_back(serial);
return new Bill(value, currency, serial);
}
}
@ -30,8 +25,8 @@ std::string CashFactory::randomString(size_t length) {
auto randchar = []() -> char {
const char charset[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
"ABCDEFGHIKLMNOPRSTUVWXYZ"
"abcdfghijklmnoqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};

View File

@ -8,12 +8,10 @@
class CashFactory {
private:
std::vector<std::string> usedSerials;
std::string randomString(size_t length);
public:
Bill * printBill(int value, Currency currency);
Coin * printCoin(int value, Currency currency);
};
#endif