#include <iostream>
class Apple
{
public:
Apple(int num, float unitCostPrice, float unitSellPrice) :
m_inventory(num),
m_unitCostPrice(unitCostPrice),
m_unitSellPrice(unitSellPrice) {}
float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
float totalSellPrice() const { return m_inventory * m_unitSellPrice;}
float netProfit() const { return totalSellPrice() - totalCostPrice(); }
private:
int m_inventory;
float m_unitCostPrice;
float m_unitSellPrice;
};
class Orange
{
public:
Orange(int num, float unitCostPrice, float unitSellPrice) :
m_inventory(num),
m_unitCostPrice(unitCostPrice),
m_unitSellPrice(unitSellPrice) {}
float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
float totalSellPrice() const { return m_inventory * m_unitSellPrice;}
float netProfit() const { return totalSellPrice() - totalCostPrice(); }
private:
int m_inventory;
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);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQXBwbGUKewpwdWJsaWM6CiAgQXBwbGUoaW50IG51bSwgZmxvYXQgdW5pdENvc3RQcmljZSwgZmxvYXQgdW5pdFNlbGxQcmljZSkgOiAKICAgIG1faW52ZW50b3J5KG51bSksCiAgICBtX3VuaXRDb3N0UHJpY2UodW5pdENvc3RQcmljZSksCiAgICBtX3VuaXRTZWxsUHJpY2UodW5pdFNlbGxQcmljZSkge30KCiAgZmxvYXQgdG90YWxDb3N0UHJpY2UoKSBjb25zdCB7IHJldHVybiBtX2ludmVudG9yeSAqIG1fdW5pdENvc3RQcmljZTsgfQogIGZsb2F0IHRvdGFsU2VsbFByaWNlKCkgY29uc3QgeyByZXR1cm4gbV9pbnZlbnRvcnkgKiBtX3VuaXRTZWxsUHJpY2U7fQogIGZsb2F0IG5ldFByb2ZpdCgpIG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