Add changed the main.cpp and the Merkel.cpp to finilize integration
This commit is contained in:
126
CM2005 Object Oriented Programming/Topic 3/3.4.11/MerkelMain.cpp
Normal file
126
CM2005 Object Oriented Programming/Topic 3/3.4.11/MerkelMain.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#include "MerkelMain.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "OrderBookEntry.h"
|
||||
#include "CSVReader.h"
|
||||
|
||||
MerkelMain::MerkelMain()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void MerkelMain::init()
|
||||
{
|
||||
loadOrderBook();
|
||||
int input;
|
||||
while(true)
|
||||
{
|
||||
printMenu();
|
||||
input = getUserOption();
|
||||
processUserOption(input);
|
||||
}
|
||||
}
|
||||
|
||||
void MerkelMain::loadOrderBook()
|
||||
{
|
||||
orders = CSVReader::readCSV("20200317.csv");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void MerkelMain::printHelp()
|
||||
{
|
||||
std::cout << "Help - your aim is to make money. Analyse the market and make bids and offers. " << std::endl;
|
||||
}
|
||||
|
||||
void MerkelMain::printMarketStats()
|
||||
{
|
||||
std::cout << "OrderBook contains : " << orders.size() << " entries" << std::endl;
|
||||
unsigned int bids = 0;
|
||||
unsigned int asks = 0;
|
||||
for(OrderBookEntry& entry : orders)
|
||||
{
|
||||
entry.orderType == OrderBookType::ask ? ++asks : ++bids;
|
||||
}
|
||||
std::cout << "Number of asks: " << asks << std::endl;
|
||||
std::cout << "Number of bids: " << bids << std::endl;
|
||||
}
|
||||
|
||||
void MerkelMain::enterOffer()
|
||||
{
|
||||
std::cout << "Mark and 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::cout << "Type in 1-6" << std::endl;
|
||||
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)
|
||||
{
|
||||
printHelp();
|
||||
}
|
||||
if (userOption == 2)
|
||||
{
|
||||
printMarketStats();
|
||||
}
|
||||
if (userOption == 3)
|
||||
{
|
||||
enterOffer();
|
||||
}
|
||||
if (userOption == 4)
|
||||
{
|
||||
enterBid();
|
||||
}
|
||||
if (userOption == 5)
|
||||
{
|
||||
printWallet();
|
||||
}
|
||||
if (userOption == 6)
|
||||
{
|
||||
gotoNextTimeframe();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user