#include <stdio.h>

const double inflation = 1.10; 
// 10% inflation since prices were fixed.
// this constant can be accessed anywhere

class Fruit {
public:
  virtual int current_unit_price() const = 0;
  // current_unit_price() doesn't modify Fruit

  void set_amount(const int amount) { amount_ = amount; }
  // set_amount() *does* modify Fruit, but doesn't modify amount.

  int get_amount() const { return amount_; }
  // get_amount again leaves Fruit unmodified.

private:
  int amount_;
};

class Apples: public Fruit {
public:
  virtual int current_unit_price() const 
  { return (int)(inflation * unit_price); }
  // note the implicit conversion from int to double, and note
  // the cast to avoid a compiler warning...

private:
  const int unit_price = 120;
  // this constant may only be used within Apple
};

class Oranges: public Fruit {
public:
  virtual int current_unit_price() const 
  { return (int)(inflation * unit_price); }
  // note the implicit conversion from int to double, and note
  // the cast to avoid a compiler warning...

private:
  const int unit_price = 60;
  // this constant may only be used within Orange
};

int price(const Fruit& fruit)
// Note that we pass a reference. We cannot pass a value because
// Fruit cannot be instatiated due to the abstract virtual function.
// We achieve the same protection as if we would pass by value by
// using the "const" keyword.
{
  return fruit.get_amount() * fruit.current_unit_price();
  // note that if we didn't have the const in both get_amount()
  // and current_unit_price(), we wouldn't be able to assure the
  // "const Fruit& fruit", and the compiler would issue an error.
}

main()
{
  Apples apples;
  Oranges oranges;

  apples.set_amount(20);
  oranges.set_amount(30);

  int total_cost = price(oranges) + price(apples);
  printf("Total cost %d\n", total_cost);

  // ... more code ...

}
