Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: cpp
os: linux
script:
- make
18 changes: 15 additions & 3 deletions Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@

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;
m_price = price;
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;
}
}
6 changes: 5 additions & 1 deletion Inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -18,4 +22,4 @@ class Inventory
friend ostream& operator<<(ostream&, const Inventory&);
};

#endif
#endif
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.