From 67393f42f41ab92219deb549f711121c4dab845b Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 15 Dec 2019 10:34:58 +0700 Subject: [usth/ICT2.2] Object Oriented Programming --- usth/ICT2.2/labwork/3/C++/shopping-cart.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 usth/ICT2.2/labwork/3/C++/shopping-cart.h (limited to 'usth/ICT2.2/labwork/3/C++/shopping-cart.h') diff --git a/usth/ICT2.2/labwork/3/C++/shopping-cart.h b/usth/ICT2.2/labwork/3/C++/shopping-cart.h new file mode 100644 index 0000000..c1450e7 --- /dev/null +++ b/usth/ICT2.2/labwork/3/C++/shopping-cart.h @@ -0,0 +1,16 @@ +#include +#include + +using namespace std; + +class ShoppingCart +{ + // quite of an improvement over the Java version + unordered_map 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 (); } +}; -- cgit 1.4.1