CJCoding With Joseph
15free / daySign inCreate account

Build a class Inventory that stores item names in a multiset<string>, so the same name can be held several times. Public methods:

1. void add(const string& name): adds one copy. 2. bool removeOne(const string& name): removes exactly ONE copy and returns true; if the item is absent, returns false and changes nothing. 3. int count(const string& name) const: how many copies are stored (0 if none). 4. void print() const: one line per distinct item in alphabetical order, as apple x2 (name, space, x, count). An empty inventory prints the single line (empty).

The test prints true/false for each removeOne and the number from count. For add apple, pear, apple; print(); removeOne("apple"); removeOne("kiwi"); print() (see Expected Output).

Do NOT write a main function.

Expected output

apple x2
pear x1
true
false
apple x1
pear x1
2
true
true
0
false
(empty)

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

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