O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.11. Pointers to Class Member Functions

The classes supporting the Fibonacci, Pell, Lucas, Square, and Pentagonal sequences are identical to those of the Triangular class except for the algorithm to generate the element sequence. In Chapter 5 we organize these classes into an object-oriented class hierarchy. In this section, we implement a general sequence class, num_sequence, to support all six sequences in a single class object. Here is our main() program:

int main() 
{ 
    num_sequence ns; 
    const int pos = 8; 
    for ( int ix = 1; ix < num_sequence::num_of_sequences(); ++ix ) 
    { 
          ns.set_sequence( num_sequence::nstype( ix )); 
          int elem_val = ns.elem( pos ); 
          display( cout, ns, pos, elem_val ); 
    } 
} 

ns is our general sequence class object. With each iteration ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required