Question: Write a C++ class that is derived from the Progression class to produce a progression where each value is the absolute value of the difference
Write a C++ class that is derived from the Progression class to produce a progression where each value is the absolute value of the difference between the previous two values. You should include a default constructor that starts with 2 and 200 as the first two values and a parametric constructor that starts with a specified pair of numbers as the first two values.
Here is the Progression class to derive from
class Progression {
public:
Progression(long f = 0) // constructor
: first(f), cur(f) { }
virtual Progression() { }; // destructor
void printProgression(int n); // print the first n values
protected:
virtual long firstValue(); // reset
virtual long nextValue(); // advance
protected: long first; // first
value long cur; // current value
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
