From f880a83136a2b73c5c3d6e766ba197ad4f33bf74 Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:13:40 -0800 Subject: [PATCH 1/6] fixed Negative inventory bug #1 --- Inventory.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Inventory.cpp b/Inventory.cpp index 57964b4..4d27766 100644 --- a/Inventory.cpp +++ b/Inventory.cpp @@ -14,7 +14,11 @@ Inventory::Inventory(string name, float price, int count) 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; + } ostream& operator<<(ostream& stream, const Inventory& item) @@ -23,4 +27,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 c83cc684b48fc2a6a4c9e74278def7d5cadff9cd Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:20:37 -0800 Subject: [PATCH 2/6] included a readme and documented inventory.cpp/h --- Inventory.cpp | 6 +++++- Inventory.h | 2 ++ README.md | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/Inventory.cpp b/Inventory.cpp index 4d27766..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,17 @@ 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() { 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 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..b55a919 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# 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 From 2028f4feb18d89c08f30dec4e9a713c694386392 Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:34:28 -0800 Subject: [PATCH 3/6] added travis ci --- .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..20f1a75 --- /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 From aaad096f2d6cb9498020e0597760797a0a0ac5b3 Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:41:26 -0800 Subject: [PATCH 4/6] no indentation in yml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20f1a75..e80d12c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ - language: cpp - os: linux - script: - - g++ -std=c+11 -Wfatal-errors *.cpp \ No newline at end of file +language: cpp +os: linux +script: + - g++ -std=c+11 -Wfatal-errors *.cpp \ No newline at end of file From c80f688c3dc930a8a3eccb39dde365d36d97fba5 Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:44:20 -0800 Subject: [PATCH 5/6] fixed yaml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e80d12c..00db022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: cpp os: linux script: - - g++ -std=c+11 -Wfatal-errors *.cpp \ No newline at end of file + - g++ -std=c++11 -Wfatal-errors *.cpp \ No newline at end of file From 70517d9759551df69ca05b3e2e4572faf389a5fb Mon Sep 17 00:00:00 2001 From: Jonathan Cheon Date: Wed, 12 Feb 2020 11:45:35 -0800 Subject: [PATCH 6/6] added build icon from travis --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b55a919..423e555 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/jcheon/Inventory.svg?branch=master)](https://travis-ci.org/jcheon/Inventory) + # Inventory # Get started