CJCoding With Joseph
15free / daySign inCreate account

Inventory That Reports the Shortfall

Most of Inventory is written: it tracks one item and how many are on the shelf. Build the exception and the method that uses it:

- OutOfStockError inherits from std::runtime_error; OutOfStockError(const std::string& item, int shortfall) makes the what() text not enough , the item, : short by and the shortfall, and keeps the shortfall for int shortfall() const - void Inventory::remove(int quantity): when quantity is more than the count, throw OutOfStockError with the item name and quantity - count, changing nothing; otherwise subtract quantity from the count

The tests read an item name and a starting count, then a list of quantities to remove. After each successful removal they print removed , the quantity, , left: and the count; after a failed one they print cannot remove: with what(), then shortfall: , the shortfall, , left: and the unchanged count. For the first test the input is bolts 10 followed by 4 8 6.

Do NOT write a main function.

Expected Output:

removed 4, left: 6
cannot remove: not enough bolts: short by 2
shortfall: 2, left: 6
removed 6, left: 0

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Exceptions
📥 Auto-Input:
bolts 10\n4 8 6\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.