Last active
February 9, 2018 21:45
-
-
Save bandrzejczak/e714e81ec6a50df627be6317494b4aca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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