CJCoding With Joseph
15free / daySign inCreate account

Build a class Inventory: 1. Inventory() — starts empty 2. void add(const string& name, int qty, double price) — appends one item (keep insertion order) 3. a free ostream& operator<<(ostream& os, const Inventory& inv) that writes the report below and returns os

Report format, every line ending in a newline: - Header line: Item left-aligned in 10 columns, then Qty right-aligned in 3 columns, then Price right-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 and Total: 0.00. Write to os, never to cout.

After adding apple (4 at 1.25) and bread (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, so print one after the last line.

Hints4 available
Topics
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.