#include <iostream>
#include <string>
#include <map>

class Item {
    public:
		Item(){};
		Item(int is, float upp, float usp) :
			in_stock(is), unit_purchase_price(upp),
			unit_sale_price(usp) {};
		int in_stock;
		float unit_purchase_price;
		float unit_sale_price;
};

class Inventory {
	private:
		typedef std::map<std::string,Item> item_map;
		typedef std::map<std::string,Item>::const_iterator im_i;
		item_map m;
	public:
		void update_item(std::string const & item, int update_quantity,
					float buy_price, float sell_price){

			Item i(update_quantity, buy_price, sell_price);
			m[item] = i;
		}
		void print_items(void) const{
			std::cout << "Item,In_Stock,Purchase_Price,Sale_Price" << std::endl;
			for( im_i i = m.begin();
				i!= m.end();
				++i)
				std::cout << i->first << "," << i->second.in_stock << ","
					<< i->second.unit_purchase_price << "," 
					<< i->second.unit_sale_price << std::endl;
		}
		float profit(std::string const & a_thing) const{
			im_i it = m.find(a_thing);
			if( it == m.end() ){
				std::cout << "No such item" << std::endl; // well shit
				return 0.0;
			}
			return static_cast<float>( it->second.in_stock)*
				(it->second.unit_sale_price - it->second.unit_purchase_price);
		}
};


int main(){
	Inventory i;
	i.update_item("A fucking toast", 1, 0.5, 100.0);
	i.update_item("oranges", 10, 1.5, 10.0);
	i.update_item("Unruly children", 6, 25, 130.50);
	i.update_item("Dwarves", 1.5, 5550, 51000.00);
	i.print_items();
	std::cout << "Profit for \"A fucking toast\": " << i.profit("A fucking toast") << std::endl;
}
