diff --git a/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.cpp b/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.cpp index a2e2aef..479f508 100644 --- a/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.cpp +++ b/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.cpp @@ -1,4 +1,5 @@ #include "Wallet.h" +#include "CSVReader.h" Wallet::Wallet() { @@ -68,3 +69,22 @@ std::string Wallet::toString() } return s; } + +bool Wallet::canFulfillOrder(OrderBookEntry order) +{ + std::vector currs = CSVReader::tokenise(order.product, '/'); + // ask + if(order.orderType == OrderBookType::ask) + { + double amount = order.amount; + std::string currency = currs[0]; + return containsCurrency(currency, amount); + } + if(order.orderType == OrderBookType::bid) + { + double amount = order.amount * order.price; + std::string currency = currs[1]; + return containsCurrency(currency, amount); + } + return false; +} \ No newline at end of file diff --git a/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.h b/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.h index b147aae..57776f8 100644 --- a/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.h +++ b/CM2005 Object Oriented Programming/Topic 5/5.1.13/Wallet.h @@ -2,6 +2,7 @@ #include #include +#include "OrderBookEntry.h" class Wallet { @@ -16,6 +17,9 @@ class Wallet /** check if the wallet contains at least this much currency */ bool containsCurrency(std::string type, double amount); + /** check if the wallet can cope with the ask or bid */ + bool canFulfillOrder(OrderBookEntry order); + /** generate a string representation of the wallet */ std::string toString();