CIS 270 Lab 6

Points: 30 Due Date: Monday September 29, 2003

This will involve simulating part of a forest. You will create a class that will represent one acre of this forest. Each acre will have some plants and animals on it. There will be birch, oak and spruce trees. There will be chipmunks, squirrels and badgers. Each acre will have different numbers of these plants and animals. In your main, you will create an array of ten of these acres. You will initialize the number of plants and animals for each acre. You can do this by using the same random number technique as you were given in Lab 4.

The main loop of the program will process each of the acres. Each time around the main loop will be one year in the forest. The simulation will run for 5 years. You will change the number of plants and animals each year. To do this, you will generate a random number between 0 and one half of the current total for each life form, this will be the change. You will then flip a coin, that is, pick a random number between 0 and 1. If the value is 0, subtract the change amount from the current total. If it is one, add it. This will become the new total.

A note on random numbers, this expression will make a random number between 0 and N-1 and store it in x.

		x = rand() % N;

After each year, you will print a report on the state of each acre. Then ask the user to type a character to go again (think _getche()). This is just to give them time to read the report.

After the 5 years, print a different report that shows for each lifeform, how many there are total in all the acres. I also printed this before the main loop started.

In main(), there should only be some loops and calls to methods on the class. For example, mine has about 26 lines, including blank lines, comments and the return at the end. And only about 3 loops, although some others are buried in methods or functions. You will have to figure out what the data elements are for the class and what methods you will need to do this task. ASK if you are unsure what this means.

I have written a solution to this and it is available here. You should be able to just download and run this to see an example of what the results should look like. Your output could be different and still be right. It's not the format but the content.

Extra Credit

Add a report after the main loop that prints the difference between the starting values for the lifeforms and the final values. Other than method calls, none of the solution can be in the main(). This is worth up to 5 points.

Deliverables:

You should turn in a listing of the program. Staple the cover sheet to that.

Notes

Think about how you will do this so you can ask questions.
ASK if you have any questions.