Extra Credit Programming Assignment

 

Write a program to perform an ecological simulation involving rabbits and wolves.

 

The basic biological facts are that wolves eat rabbits and rabbits eat grass.  Both breed, although rabbits are much faster.  There is plenty of grass, so wolves are the only obstacle to the population increase of rabbits.  The wolf supply increases with the supply of rabbits.  The day‑to‑day changes in the rabbit population (r) and the wolf population (w) can be expressed via the following formulas:

 

                        r  (tomorrow) = (1 + A) * r    C * r * w   (today)

                        w (tomorrow) = (1 ‑ B) * w  +  C * D * r * w   (today)   

 

where

                        A = 0.01                      represents the fractional increase in rabbit population with no competition.  

                        B = 0.005                    represents the fractional decrease in wolf population with no rabbits to eat.

                        C = 0.00001                represents the likelihood that a wolf will encounter and eat a rabbit.

                        D = 0.01                      represents the fractional increase in wolf population attributed to an eaten rabbit.

 

Write your program to monitor the daily fluctuations of rabbits and wolves over a 1,000 day period.  Print out the results, both to an output file and to the screen, every 25 days.  Read in the initial number of rabbits and wolves from the keyboard.

 

Your output must look like the following:

 

Initial number of rabbits = 10000

Initial number of wolves  = 1000

 

   Day          Rabbits          Wolves

    25          XXXXXXX         XXXXXXX

    50          XXXXXXX         XXXXXXX

  etc.            etc.            etc.

  1000          XXXXXXX         XXXXXXX                 

 

Maximum number of rabbits = 210504

Maximum number of wolves  = 2949

 

 

Notes

 

1.         To determine if it is the 25th day, use the "%" operator.  That is, use a statement like

 

                        if (day % 25 == 0)

                                        outfile << ...  ;

 

2.         Use an integer variable for the number of rabbits and wolves since there cannot be fractional parts of rabbits or wolves.

 

3.         As always, failure to save your program before running it may be dangerous to your program's health.

 

4.         Start the simulation with 10,000 rabbits and 1,000 wolves (this would be for day = 0).

 

5.         Define the constants A, B, C, and D as named constants at the top of your program.  Make the total number of days a named constant also.

 

 

 

Make sure your program works correctly.

 


Back to the Main Menu