diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.cpp b/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.cpp new file mode 100644 index 0000000..d2f3f0e --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.cpp @@ -0,0 +1,18 @@ +#include "OrderBookEntry.h" + +OrderBookEntry::OrderBookEntry +( + double price, + double amount, + std::string timestamp, + std::string product, + OrderBookType orderType +) +: +price{price}, +amount{amount}, +timestamp{timestamp}, +product{product}, +orderType{orderType} +{ +} \ No newline at end of file diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.h b/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.h new file mode 100644 index 0000000..6f41233 --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.3/OrderBookEntry.h @@ -0,0 +1,25 @@ +#include + +enum class OrderBookType +{ + bid, + ask +}; + +class OrderBookEntry +{ + public: + OrderBookEntry + ( + double price, + double amount, + std::string timestamp, + std::string product, + OrderBookType orderType + ); + double price; + double amount; + std::string timestamp; + std::string product; + OrderBookType orderType; +}; \ No newline at end of file diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.3/a.exe b/CM2005 Object Oriented Programming/Topic 2/2.5.3/a.exe new file mode 100644 index 0000000..f9e7c31 Binary files /dev/null and b/CM2005 Object Oriented Programming/Topic 2/2.5.3/a.exe differ diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.3/main.cpp b/CM2005 Object Oriented Programming/Topic 2/2.5.3/main.cpp new file mode 100644 index 0000000..fcaa681 --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.3/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include "OrderBookEntry.h" + +double computeAveragePrice(std::vector& entries) +{ + double avg = 0; + for(unsigned int i=0; i orders; + + orders.push_back( OrderBookEntry{ + 10000, + 0.002, + "2020/03/17 17:01:24.884492", + "BTC/USDT", + OrderBookType::bid}); + + orders.push_back( OrderBookEntry{ + 50000, + 0.002, + "2020/03/17 17:01:24.884492", + "BTC/USDT", + OrderBookType::bid}); + + std::cout << "Average price: " << computeAveragePrice(orders) << std::endl; +} \ No newline at end of file