Aging, Breeding, Dying programming assignment
Some ecologists from upstate New York would like to adapt the fish simulation to study the growth over
time of populations of fish, given limited resources. They would
like to study what happens when fish breed and die over time. They plan to use the simulation model
as a means of studying fish populations in lakes in New York State.
The ecologists want to make the following assumptions about the fish:
- Fish age
- Each fish can have its own probabilities of breeding and dying.
- Fish die at any age with the same probability; that probability is a characteristic of each fish.
- Fish breed between the ages of 10 and 20 (as measured by steps in the simulation)
- The number of offspring produced when fish breed is dependent on the unused resources
(i.e. empty space) which are available
- A breeding fish produces an offspring in each neighboring empty location with its given probability
- The probability of producing an offspring in one empty neighboring position is independent
of other neighboring positions
- Each offspring that is produced inherits its probabilities of breeding and dying from its parent
In addition the ecologists would like to be able to distinguish among fish of different ages in the display:
- Display older fish differently from younger fish
- once fish reach breeding age, change the way in which they are displayed
Download the following files and place them in a folder called LiveBreedDie
Create new LJHS project called Breed and store the project in the LiveBreedDie folder. Move fish.dat
into the LiveBreedDie folder. Add all *.cpp files to your project then run the project.
If you have warnings with RandGen, remove randGen.cpp from your project.
You should get a two-dimensional array display.
Instead of displaying spaces between the fishes in the output, display a dot ('.') for the space.
Determine which class needs to be editied and then edit the file so that dots '.''s are output
instead of blank spaces.
Assignment
- Add an age characteristic to the fish.
- Add a data member myAge to the Fish class which represents the age of the fish.
- Add a public member function Age to the Fish class that returns the age of the fish.
- Add to all constructors an initialized age of zero.
- Add a probability of dying and a probability of breeding to the fish.
- Add data members myProbBreed and myProbDie to the fish class (floating point values)
- The specifications for a fish data file are changed so that each position
for a fish is followed in
order by its age, its probability of dying, its probability of breeding. Download the file
FishReal.dat for your testing and reports.
- A new Fish constructor takes an age, a probability of dying and a probability of breeding as
additional parameters that are used to initialize the corresponding fish data members.
- The declaration of existing fish constructors should not be changed. They should
assign appropriate default values to the new data members.
- The Environment constructor should be changed so that it reads a file with the
new format and passes the new information for each fish as parameters to the
AddFish function.
- The Environment member function AddFish should be changed so that it takes
three additional parameters: age, probability of dying, probability of
breeding, and creates Fish with those values assigned to the corresponding data members.
- Create a new Environment member function RemoveFish that removes a Fish at a
given Position, passed as a parameter, from the Environment.
- Recall that positions in the Environment data member myWorld that are
"empty" contain a fish that is undefined.
- Be sure to maintain the state of the Environment correctly.
- Create a new Fish member function Act that will be responsible for all of
the actions of a fish on each step.
- Act should cause the fish to die with the probability of dying for this fish.
- If the fish dies, the Act function must ask for it to be removed from the
environment by calling the new Environment member function RemoveFish
- Act should have fish that are breeding age (10 to 20 steps "old" inclusive) breed
- It is appropriate to have Act call a new private "helper" Fish member function Breed
- How should the ages of breeding be represented in the model?
- Act should update the fish's age.
- The Move member function should be made private, since its function now becomes
part of a a fish's actions, represented by the Act function.
- Act should call the Move function. Fish that breed may still move into empty
neighboring positions that have not been filled with offspring.
- Modify the Fish member function ShowMe so that fish of breeding age or older appear
different from younger fish.
- Younger fish can be represented with lower case letters, older with upper case
- After the 26th fish, younger fish can be represented by the character 'o' and older by
the character 'O'.
- Use or modify calls to DebugPrint appropriately, so that they can be used to check the
correct functioning of the modified program.
- Modify the Simulation member function Step so that it calls Act instead of Move.
- Also modify the simulation class so that Run function will stop if there are no more fish
to display, otherwise it will run the number of times required. (You will need to add a function
to the Environment class.)
Now let's add the good stuff!
- Add a sex type to each fish (male, female). When fish are born they are equally likely to be
male as they are female. Female fish can only breed if a breeding age male fish is within
x units. The probability of breeding is the same as the original problem.
- You will have to alter the fish.dat data file, and Environment functions that need the new
information about the sex of a fish.
- Change your fish display so that juvenile males appear as 'm', breeding males as 'M', and old
non-breeding males as '^'. Juvenile females should be displayed as ''f', breeding females as
'F', and older non-breeding females as '&'.
- The probabilities of breeding and dying of offspring should be
a random value between the probabilities
of the parents. Sex type should be a 50/50 random chance.
- Determine what distance value from male to female fish produces an equal balance of breeding and dying.
What to turn in
- Report explaining how you implemented the additions and changes.
- Code for any header or implementation file altered, with comments indicating the
code changes. Use a highlight marker and highlight all your changes/additions.
- Output should show the original location of the fish loaded in by the fish.dat data
file, followed by displaying the environment after 10 steps, 20 steps and 100 steps.
- How you implemented the sex of the fish.
- How you computed the distance between fish to allow breeding.
- What is the distance between that produces a positive environment?