blob: c1450e78bffa23d04afdbebc17f4a4ab33af6e30 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include <string>
#include <unordered_map>
using namespace std;
class ShoppingCart
{
// quite of an improvement over the Java version
unordered_map<string, int> contents;
public:
void add_to_cart (string item) { contents[item]++; }
void remove_from_cart (string item) { contents[item] = 0; }
// to make this class useful anyhow
int count (string item) { return contents[item]; }
void check_out () { contents.clear (); }
};
|