Suspending disbelief, suppose that you decide to improve the
rabbits program by dividing it into three files, one for each of
the three key functions. One file, rabbits.cxx
, contains
main
and rabbits
:
// The rabbits.cxx file #include// Space reserved to include files int rabbits (int n) { if (n == 0 || n == 1) return 1; else return previous_month (n) + penultimate_month (n);} main ( ) { int months; cout << "Please supply the number of months. << endl; cin >> months; cout << "After " << months << " months, there are " << rabbits(months) << "rabbits." << endl; }
The other files, previous.cxx
and penultimate.cxx
are
simpler:
// The previous.cxx file // Space reserved to include files int previous_month (int n) {return rabbits ((n - 1));} // The penultimate.cxx file // Space reserved to include files int penultimate_month (int n) {return rabbits ((n - 2));}