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 diff --git a/Inventory.cpp b/Inventory.cpp index de8e7b8..9a4b2fc 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -4,7 +4,12 @@ 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; @@ -12,14 +17,21 @@ Inventory::Inventory(string name, float price, int count) m_in_stock = count; } +// Decrements stock of item, unless quantity is 0 void Inventory::sell() { - m_in_stock--; + if (m_in_stock == 0){ + cout << "Sorry, that item is out of stock.\n"; + } + else { + m_in_stock--; + } } +// Prints information about the item ostream& operator<<(ostream& stream, const Inventory& item) { stream << item.m_name << " $" << std::fixed << std::setprecision(2) << item.m_price; return stream; -} \ No newline at end of file +} 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..675cf53 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +[![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. + +To build, simply type "make" in the command line, then run the executable.