Home Segments Index Top Previous Next

701: Mainline

The following is the complete collection of cxx files that comprise the rabbits program:

// The rabbits.cxx file 
#include  
#include "rabbits.h" 
#include "previous.h" 
#include "penultimate.h" 
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 previous.cxx file 
#include "previous.h" 
#include "rabbits.h" 
int previous_month (int n) {return rabbits ((n - 1));} 
  
// The penultimate.cxx file 
#include "penultimate.h" 
#include "rabbits.h" 
int penultimate_month (int n) {return rabbits ((n - 2));}