diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.cpp b/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.cpp new file mode 100644 index 0000000..3418d96 --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.cpp @@ -0,0 +1,135 @@ +#include "MerkelMain.h" +#include + +MerkelMain::MerkelMain() +{ + init(); +} + +void MerkelMain::init() +{ + loadOrderBook(); + int input; + while(true) + { + printMenu(); + input = getUserOption(); + processUserOption(input); + } +} + +void MerkelMain::loadOrderBook() +{ + 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}); +} + +void MerkelMain::printMenu() +{ + // 1 print help + std::cout << "1: Print help" << std::endl; + // 2 print exchange stats + std::cout << "2: Print exchange stats" << std::endl; + // 3 make an offer + std::cout << "3: Make an offer" << std::endl; + // 4 make a bid + std::cout << "4: Make a bid " << std::endl; + // 5 print wallet + std::cout << "5: Print wallet " << std::endl; + // 6 continue + std::cout << "6: Continue" << std::endl; + + std::cout << "==========" << std::endl; + std::cout << "Enter an option: " << std::endl; +} + +void MerkelMain::printHelp() +{ + std::cout << "Help - Your aim is to analyze the market, make bid and offers and make money." << std::endl; +} + +void MerkelMain::printMarketStats() +{ + //std::cout << "Market looks good" << std::endl; + std::cout << "OrderBook contains " << orders.size() << " entries." << std::endl; + std::cout << orders[0].price << std::endl; + std::cout << orders[1].price << std::endl; +} + +void MerkelMain::enterOffer() +{ + std::cout << "Make an offer - Enter the amount: " << std::endl; +} + +void MerkelMain::enterBid() +{ + std::cout << "Make a bid - Enter the amount: " << std::endl; +} + +void MerkelMain::printWallet() +{ + std::cout << "Your wallet is empty. " << std::endl; +} + +void MerkelMain::goToNextTimeFrame() +{ + std::cout << "Going to next time frame. " << std::endl; +} + +int MerkelMain::getUserOption() +{ + int userOption; + std::cin >> userOption; + std::cout << "You chose: " << userOption << std::endl; + return userOption; +} + +void MerkelMain::processUserOption(int userOption) +{ + if (userOption == 0) // bad input + { + std::cout << "Invalid choice. Choose 1-6" << std::endl; + } + + if (userOption == 1) // Option 1 - Help + { + printHelp(); + } + + if (userOption == 2) // Option 2 - Stats + { + printMarketStats(); + } + + if (userOption == 3) // Option 3 - Offer + { + enterOffer(); + } + + if (userOption == 4) // Option 4 - Bid + { + enterBid(); + } + + if (userOption == 5) // Option 5 - Wallet + { + printWallet(); + } + + if (userOption == 6) // bad input + { + goToNextTimeFrame(); + } + return; +} \ No newline at end of file diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.h b/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.h new file mode 100644 index 0000000..995d53a --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.13/MerkelMain.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include "OrderBookEntry.h" + +class MerkelMain +{ + public: + MerkelMain(); + private: + /* Starts the sim */ + void init(); + void loadOrderBook(); + void printMenu(); + void printHelp(); + void printMarketStats(); + void enterOffer(); + void enterBid(); + void printWallet(); + void goToNextTimeFrame(); + int getUserOption(); + void processUserOption(int userOption); + std::vector orders; +}; \ No newline at end of file diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.13/OrderBookEntry.cpp b/CM2005 Object Oriented Programming/Topic 2/2.5.13/OrderBookEntry.cpp new file mode 100644 index 0000000..d2f3f0e --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.13/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.13/OrderBookEntry.h b/CM2005 Object Oriented Programming/Topic 2/2.5.13/OrderBookEntry.h new file mode 100644 index 0000000..60bfe3c --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.13/OrderBookEntry.h @@ -0,0 +1,26 @@ +#pragma once +#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.13/a.exe b/CM2005 Object Oriented Programming/Topic 2/2.5.13/a.exe new file mode 100644 index 0000000..706af88 Binary files /dev/null and b/CM2005 Object Oriented Programming/Topic 2/2.5.13/a.exe differ diff --git a/CM2005 Object Oriented Programming/Topic 2/2.5.13/main.cpp b/CM2005 Object Oriented Programming/Topic 2/2.5.13/main.cpp new file mode 100644 index 0000000..b6b2991 --- /dev/null +++ b/CM2005 Object Oriented Programming/Topic 2/2.5.13/main.cpp @@ -0,0 +1,10 @@ +#include +#include +#include +#include "OrderBookEntry.h" +#include "MerkelMain.h" + +int main() +{ + MerkelMain app{}; +} \ No newline at end of file