Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 21:46
Show Gist options
  • Select an option

  • Save bandrzejczak/4bef7e9e2e0433e75c9eb0167e302e83 to your computer and use it in GitHub Desktop.

Select an option

Save bandrzejczak/4bef7e9e2e0433e75c9eb0167e302e83 to your computer and use it in GitHub Desktop.
class ListStockExchange : public StockExchange {
private:
std::list<Trade *> * trades;
public:
ListStockExchange() {
trades = new std::list<Trade *>();
}
~ListStockExchange(){
auto i = trades->begin();
while (i != trades->end())
{
delete (*i);
trades->erase(i++);
}
delete trades;
}
void order(int ticket, int amount, int price, bool buy) {
trades->push_back(new Trade(ticket,amount,price,buy));
}
double dayBalance() {
double balance = 0;
for(auto tradesIterator = trades->begin(); tradesIterator != trades->end(); tradesIterator++)
balance += (*tradesIterator)->amount * (*tradesIterator)->price * ((*tradesIterator)->buy ? 1 : -1);
return balance;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment