Exercise 2.3
Separate the function to calculate the Pentagonal numeric sequence implemented in Exercise 2.2 into two functions. One function should be inline; it checks the validity of the position. A valid position not as yet calculated causes the function to invoke a second function that does the actual calculation.
I factored calc_elements() into the inline calc_elems() that if necessary calls the second function, really_calc_elems(). To test this reimplementation, I substituted the call of calc_elements() in the Exercise 2.2 function with that of calc_elems().
extern void really_calc_elems( vector<int>&, int ); inline bool calc_elems( vector<int> &vec, int pos ) { if ( pos <= 0 || pos > 64 ){ cerr << "Sorry. Invalid position: " << pos << ...
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.