Aging, Breeding, Dying programmign assignment AP-A
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
Make a copy of your Movement folder and call it LiveBreedDie.
Use the edited files to start the assignment. If you did not complete the previous
"Freedom of Movement" assignment, download the files again into a folder called
LiveBreddDie (see "Freedom of Movement" assignment for
original files.)
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 construtors an initialized age of zero.
- Add a probabilty 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 Enviroment class.)
- Draw a new set of
'Class Diagrams'
that show the new functions and the
collaborations among the classes.
What to turn in
- Cover page with the assignment, date, and your name on it.
- Write a report explaining how you implemented the additions and changes.
- Modified class diagrams.
- Code for any header or implmentation file altered, with comments indicating the
code changes.
- Output should show the original location of the fish loaded in by the fish.dat data
file, followed by displaying the environment afters 10 steps, 20 steps and 100 steps.