October 1999
Beginner
304 pages
7h 11m
English
Recall that fibon_elem() returns the Fibonacci element at a user-specified position within the sequence. In our original implementation, it calculates the sequence up to the requested position with each invocation. It also tests whether the requested position is reasonable. We can simplify its implementation by factoring subtasks into separate functions:
bool is_size_ok( int size ) { const int max_size = 1024; if ( size <= 0 || size > max_size ) { cerr << "Oops: requested size is not supported : " << size << " -- can't fulfill request.\n"; return false; } return true; } // calculate up to size elements of Fibonacci sequence // return address of static container holding elements const vector<int> *fibon_seq( ...Read now
Unlock full access