CJCoding With Joseph
15free / daySign inCreate account

OrderBook Deletes Every Order Pointer

Order 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 absent
`

The 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
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
Topics:
Pointers
📥 Auto-Input:
3\n101 10\n102 20\n103 15\n102\n103\n
This input is automatically fed to your program's stdin
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.