OrderBook Deletes Every Order Pointer
mediumQuestion 702Order is already written in the starter — leave it alone. Write OrderBook, which stores raw Order* pointers in a private std::vector<Order*> orders; and OWNS every one of them.
Public interface:
~OrderBook(); // delete every Order still in the vector
void add(int id, int qty); // push_back a new Order
int count() const; // how many orders are in the book
int totalQty() const; // the sum of every order's qty
int qtyOf(int id) const; // the qty of the order with that id, or 0 if there is none
void removeById(int id); // delete that Order and take it out of the vector; do nothing if absentThe driver reads k, then k lines of id qty, then the id to remove and the id to look up. For the input:
3
101 10
102 20
103 15
102
103the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
before 3 45 after 2 25 qty 15 gone 0
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.