language: C++ 4.7.2 (gcc-4.7.2)
date: 122 days 19 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
 
class Fruit{
public:
  virtual   float   totalCostPrice() const = 0;
  virtual   float totalSellPrice() const = 0;
  virtual float netProfit() const = 0;
};
 
class Fruit_PI : virtual public Fruit {
protected:
  int m_inventory;
public:
  Fruit_PI( int num) : m_inventory(num) {}
 
  virtual float netProfit() const { return totalSellPrice() - totalCostPrice(); }
};
 
class Apple : virtual public Fruit, private Fruit_PI {
private:
  float m_unitCostPrice;
  float m_unitSellPrice;
public:
  Apple(int num, float unitCostPrice, float unitSellPrice) : 
    Fruit_PI(num),
    m_unitCostPrice(unitCostPrice),
    m_unitSellPrice(unitSellPrice) {}
 
  virtual float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
 
  virtual float totalSellPrice() const { return m_inventory * m_unitSellPrice;}
};
 
class Orange : virtual public Fruit, private Fruit_PI {
private:
  float m_unitCostPrice;
  float m_unitSellPrice;
public:
  Orange(int num, float unitCostPrice, float unitSellPrice) : 
    Fruit_PI(num),
    m_unitCostPrice(unitCostPrice),
    m_unitSellPrice(unitSellPrice) {}
 
  virtual float totalCostPrice() const { return m_inventory * m_unitCostPrice; }
 
  virtual float totalSellPrice() const { return m_inventory * m_unitSellPrice;}
};
 
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);
}