The four space-separated message formats below describe the placement, modifying, and…
- User
The four space-separated message formats below describe the placement, modifying, and trading (i.e. "fill"ing) of orders at a securities exchange throughout the day:
new <buy | sell> modify modify fill Terminology:
A chain (of orders) refers to a “new” order message, followed by 0 or more "modify"s, each referencing the previous message in the chain by order id. (Example below.) The volume weighted average price (“vwap”) of one or more fill messages is the total money exchanged divided by the total number of shares exchanged. For example, fills for 5 shares at 100.00, 10 shares at 130.00, and 5 shares at 150.00, would have vwap of (5100.00 + 10130.00 + 5*150.00) / (5 + 10 + 5) = (500.00 + 1300.00 + 750.00) / 20 = 2550.00 / 20 = 127.50. Due to race conditions at the exchange, a “fill” message’s order-id can be from any “new” or “modify” message previously seen in the input messages.
TASK
Provide efficient (in terms of big-O efficiency of operations on containers) and clean implementation for the function:
vector average_prices(const vector& messages);
… which is passed a sequence of exchange messages - as described above - and must return a vector containing strings with the format:
solve above question in C++
- Assistant