← Back to Streams
Question 642
Inventory Report operator<<
Inventory Report operator<<
Build a classInventory: 1.Inventory()— starts empty 2.void add(const string& name, int qty, double price)— appends one item (keep insertion order) 3. a freeostream& operator<<(ostream& os, const Inventory& inv)that writes the report below and returnsosReport format, every line ending in a newline: - Header line:Itemleft-aligned in 10 columns, thenQtyright-aligned in 3 columns, thenPriceright-aligned in 8 columns - One line per item, in the order added: name left-aligned in 10 columns, qty right-aligned in 3 columns, price right-aligned in 8 columns with exactly 2 decimals - Last line:Total:followed by the sum of qty times price over all items, with exactly 2 decimals An empty inventory prints only the header line andTotal: 0.00. Write toos, never tocout. After addingapple(4 at 1.25) andbread(3 at 2.50) (see Expected Output). Do NOT write a main function.
Expected Output:
Item Qty Price apple 4 1.25 bread 3 2.50 Total: 12.50 Item Qty Price Total: 0.00 Item Qty Price pen 12 0.50 Total: 6.00
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsostream
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.