diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..00db022 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: cpp +os: linux +script: + - g++ -std=c++11 -Wfatal-errors *.cpp \ No newline at end of file diff --git a/Inventory.cpp b/Inventory.cpp index 57964b4..592e041 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -5,6 +5,8 @@ using std::string; using std::ostream; + +// Inventory object constructor Inventory::Inventory(string name, float price, int count) { m_name = name; @@ -12,15 +14,21 @@ Inventory::Inventory(string name, float price, int count) m_in_stock = count; } +// Inventory method that decrements stocks when it is sold +// or prints sold out if there is none. void Inventory::sell() { - m_in_stock--; + if(m_in_stock > 0) + m_in_stock--; + else + std::cout << "Sorry, that item is out of stock" << std::endl; } +// Prints name and price 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..faef493 100644 --- a/Inventory.h +++ b/Inventory.h @@ -5,6 +5,8 @@ using std::string; using std::ostream; +// Inventory class that stores name, price, and in_stock variables. +// Has funtions that decrement in_stock when it is sold. class Inventory { private: diff --git a/README.md b/README.md new file mode 100644 index 0000000..423e555 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +[![Build Status](https://travis-ci.org/jcheon/Inventory.svg?branch=master)](https://travis-ci.org/jcheon/Inventory) + +# Inventory + +# Get started +- To begin, grab the repo into your machine. +- cd into the repo. +- type 'make' to make an executable +- give inputs 'S' (sell) or 'Q'(quit) \ No newline at end of file