From 3cd0f98c175dd382036ede3cbe13d8c585671e5e Mon Sep 17 00:00:00 2001 From: dragongoat Date: Wed, 12 Feb 2020 11:12:04 -0800 Subject: [PATCH 1/4] Fixes #1 --- Inventory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Inventory.cpp b/Inventory.cpp index 57964b4..501395b 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -4,6 +4,7 @@ using std::string; using std::ostream; +using std::cout; Inventory::Inventory(string name, float price, int count) { @@ -14,7 +15,12 @@ Inventory::Inventory(string name, float price, int count) void Inventory::sell() { - m_in_stock--; + if (m_in_stock == 0){ + cout << "Sorry, that item is out of stock.\n"; + } + else { + m_in_stock--; + } } ostream& operator<<(ostream& stream, const Inventory& item) @@ -23,4 +29,4 @@ ostream& operator<<(ostream& stream, const Inventory& item) << " $" << std::fixed << std::setprecision(2) << item.m_price; return stream; -} \ No newline at end of file +} From 9046632f609fe7e686635c5b31caa267af7b8ed8 Mon Sep 17 00:00:00 2001 From: dragongoat Date: Wed, 12 Feb 2020 11:20:00 -0800 Subject: [PATCH 2/4] Added documentation. Fixes #2 --- Inventory.cpp | 8 +++++++- Inventory.h | 6 +++++- README.md | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/Inventory.cpp b/Inventory.cpp index 501395b..d455ad1 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -5,7 +5,11 @@ using std::string; using std::ostream; using std::cout; - + +// Constructor +// @param string name - The name of the item to add +// @param float price - The price of the item to add +// @param int count - The quantity of the item to add Inventory::Inventory(string name, float price, int count) { m_name = name; @@ -13,6 +17,7 @@ Inventory::Inventory(string name, float price, int count) m_in_stock = count; } +// Decrements stock of item, unless quantity is 0 void Inventory::sell() { if (m_in_stock == 0){ @@ -23,6 +28,7 @@ void Inventory::sell() } } +// Prints information about the item ostream& operator<<(ostream& stream, const Inventory& item) { stream << item.m_name diff --git a/Inventory.h b/Inventory.h index c52d5d8..4d465d0 100644 --- a/Inventory.h +++ b/Inventory.h @@ -5,11 +5,15 @@ using std::string; using std::ostream; +// This class is used to keep track of an item in the shop's inventory. class Inventory { private: + // Name of the item string m_name; + // Price of the item float m_price; + // Quantity of item left in stock int m_in_stock; public: @@ -18,4 +22,4 @@ class Inventory friend ostream& operator<<(ostream&, const Inventory&); }; -#endif \ No newline at end of file +#endif diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9a70f4 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ + + +This application simulates a shop, where items can be added to the shop's stock and sold. + +To build, simply type "make" in the command line, then run the executable. From 8dc6fe44664fe05a1e3e7e250122498fd34acc36 Mon Sep 17 00:00:00 2001 From: dragongoat Date: Wed, 12 Feb 2020 11:20:17 -0800 Subject: [PATCH 3/4] Added travisCI --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e0e6c86 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: cpp +os: linux +script: + - make From 39ef20a67f3624078806d2a6022f6a8ac922dcf2 Mon Sep 17 00:00:00 2001 From: dragongoat Date: Wed, 12 Feb 2020 11:21:13 -0800 Subject: [PATCH 4/4] Added badge to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9a70f4..675cf53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - +[![Build Status](https://travis-ci.org/Dragongoat/Inventory.svg?branch=master)](https://travis-ci.org/Dragongoat/Inventory) This application simulates a shop, where items can be added to the shop's stock and sold.