To gain a more complete understanding of multiple-file programs, you need to learn how to distribute not only class definitions, but also function prototypes and ordinary function definitions among header files and source-code files.
As an illustration, consider again the three-function version of the
rabbit-calculating program introduced in Chapter 23. Recall
that the purpose of the program is to calculate the number of rabbits after
n months, given one newborn female rabbit at time 0
.
The program contains three key functions:
int rabbits (int n) { if (n == 0 || n == 1) return 1; else return previous_month (n) + penultimate_month (n);} int previous_month (int n) {return rabbits ((n - 1));} int penultimate_month (int n) {return rabbits ((n - 2));}