Question: /** Test program for the progression classes */ int main() { Progression prog: // test ArithProgression cout printProgression (10): cout printProgression (10): // test GeomProgression







/** Test program for the progression classes */ int main() { Progression prog: // test ArithProgression cout printProgression (10): cout printProgression (10): // test GeomProgression cout printProgression(10): cout printProgression (10); // test Fibonacci Progression cout printProgression(10): cout printProgression(10): return EXIT_SUCCESS: // successful execution } Copy the programs, execute and test with several inputs Trace the version of each function that were called class GeomProgression public Progression { // geometric progression public: GeomProgression(long b = 2): // constructor protected: virtual long nextValue(): // advance protected: long base; // base value }; GeomProgression::GeomProgression(long b) // constructor : Progression(1), base(b) { } // advance by multiplying long GeomProgression:: nextValue() { cur *= base; return cur: } class ArithProgression : public Progression { // arithmetic progression public: ArithProgression(long i = 1); // constructor protected: virtual long nextValue(); // advance protected: long inc; // increment }; ArithProgression::ArithProgression(longi) : Progression(), inc(i) { } // constructor // advance by adding long ArithProgression:nextValue() { cur += inc; return cur; } class FibonacciProgression : public Progression { // Fibonacci progression public: FibonacciProgression(long f 0, long s= 1); // constructor protected: virtual long firstValue(); // reset virtual long nextValue(); // advance protected: long second; // second value long prev; // previous value }; FibonacciProgression:: FibonacciProgression (long f, long s) : Progression(f), second(s), prev(second first) { } // reset cur = long FibonacciProgression::firstValue() { first; prev = second first; return cur; } // create fictitious prev // advance - long FibonacciProgression:: nextValue() { long temp prev; prev = cur; cur += temp; return cur; } /** Test program for the progression classes */ int main() { Progression prog: // test ArithProgression cout printProgression (10): cout printProgression (10): // test GeomProgression cout printProgression(10): cout printProgression (10); // test Fibonacci Progression cout printProgression(10): cout printProgression(10): return EXIT_SUCCESS: // successful execution } Copy the programs, execute and test with several inputs Trace the version of each function that were called class GeomProgression public Progression { // geometric progression public: GeomProgression(long b = 2): // constructor protected: virtual long nextValue(): // advance protected: long base; // base value }; GeomProgression::GeomProgression(long b) // constructor : Progression(1), base(b) { } // advance by multiplying long GeomProgression:: nextValue() { cur *= base; return cur: } class ArithProgression : public Progression { // arithmetic progression public: ArithProgression(long i = 1); // constructor protected: virtual long nextValue(); // advance protected: long inc; // increment }; ArithProgression::ArithProgression(longi) : Progression(), inc(i) { } // constructor // advance by adding long ArithProgression:nextValue() { cur += inc; return cur; } class FibonacciProgression : public Progression { // Fibonacci progression public: FibonacciProgression(long f 0, long s= 1); // constructor protected: virtual long firstValue(); // reset virtual long nextValue(); // advance protected: long second; // second value long prev; // previous value }; FibonacciProgression:: FibonacciProgression (long f, long s) : Progression(f), second(s), prev(second first) { } // reset cur = long FibonacciProgression::firstValue() { first; prev = second first; return cur; } // create fictitious prev // advance - long FibonacciProgression:: nextValue() { long temp prev; prev = cur; cur += temp; return cur; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
