← Back to Pointers
Question 702
OrderBook Deletes Every Order Pointer
OrderBook Deletes Every Order Pointer
Orderis already written in the starter — leave it alone. WriteOrderBook, which stores rawOrder*pointers in a privatestd::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 absent`The driver readsk, thenklines ofid qty, then the id to remove and the id to look up. For the input:`3 101 10 102 20 103 15 102 103`` the 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 — 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.