#include <iostream>

template <class ParticularFruit>
struct FruitBase
{
    FruitBase(int num) : m_inventory(num) {}

	float netProfit() const
	{
		auto && particular_fruit = static_cast<const ParticularFruit &>(*this);
		return particular_fruit.totalSellPrice() - particular_fruit.totalCostPrice();
	}

protected:
	int m_inventory;
};

struct Apple : FruitBase<Apple>
{
	Apple(int num, float unitCostPrice, float unitSellPrice) : 
		FruitBase(num),
		m_unitCostPrice(unitCostPrice),
		m_unitSellPrice(unitSellPrice) {}

	float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
	float totalSellPrice() const { return m_inventory * m_unitSellPrice; }

private:
	float m_unitCostPrice;
	float m_unitSellPrice;
};

struct Orange : FruitBase<Orange>
{
	Orange(int num, float unitCostPrice, float unitSellPrice) : 
		FruitBase(num),
		m_unitCostPrice(unitCostPrice),
		m_unitSellPrice(unitSellPrice) {}

	float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
	float totalSellPrice() const { return m_inventory * m_unitSellPrice; }

private:
	float m_unitCostPrice;
	float m_unitSellPrice;
};

template <typename Fruit>
void print_net_profit(const Fruit & fruit)
{
	std::cout << "Net profit at current prices = $ " << fruit.netProfit() << std::endl;
}

int main()
{
	Apple apple(100, 4.00, 4.25);
	Orange orange(50, 7.00, 7.25);
 
	print_net_profit(apple);
	print_net_profit(orange);
}
