Code Fragment: Fib



class FibonacciProgression : public Progression {
protected:                              // member data
  long second;				// second value
  long prev;				// previous value

  virtual long firstValue() {		// reset and return first value
    cur = first;
    prev = second - first;		// create fictitious previous
    return cur;
  }
  virtual long nextValue() {		// advance by (current + previous)
    long temp = prev;
    prev = cur;
    cur += temp;
    return cur;
  }
public:
  					// constructor from first and second
  FibonacciProgression(long f = 0, long s = 1)
    : Progression(f) {			// initialize base with first
    second = s;
    prev = second - first;		// create fictitious previous
  }
};