Project 2: Using Arrays of Classes
Due Friday, March 1, at 9:00 AM
The domestic chicken is descended from the Red Jungle Fowl, native to Southern Asia. The day length changes in its native habitat are less extreme than those further North, and as such, domestic chickens in the North will (without intervention) will cease laying eggs in the Fall, and not resume until Spring. Supplemental lighting can be used to alleviate this, since chickens determine day length based on light rather than Sun position or temperature or any other factor.
When maintaining a chicken flock, commercial egg producers prefer to keep a flock of young birds, because egg production drops off rapidly as the chickens age. To do this, chickens are culled at about 3 years of age. However, backyard flocks are often kept longer, perhaps even until the chickens die of old age. If a flock starts off as chicks, this will not have any immediate effect. However, after a few years, the chickens will be old and not dead, which will result in a drop in production. As chickens die of old age and are replaced, productivity will recover and stabilize, although at a level lower than a flock managed with age-based culling.
Develop a simulation which will allow both factors to be evaluated. Specifically, your simulation should be able to compare egg production:
- With no supplemental light or culling
- With supplemental light, but no culling
- With no supplemental light, but with culling
- With supplemental light and culling
Most design decisions can be made however you like. However, the program must meet the following guidelines:
- Chickens must be represented by an object with data and methods
- Instances of the chicken class must be stored in an array, STL vector, or other data structure
- All four simulations must show egg totals per year and over the entire simulation period
There is a file in the class examples called day_lengths which has 365 entries, each of which is the length of a day. It starts on January 1. You can use this for the day length without supplemental light. With supplemental light, don't decrease day length in June, but maintain maximal-length days until February. In February, switch to natural-length days until June. This is to allow the chickens to molt (replace feathers). They will stop laying during this period.
Use an algorithm such as the following to determine if a chicken will change laying state:
hours = number of hours in the current day
lmax = maximum day length experienced during the past 30 days
lmin = minimum day length experienced during the past 30 days
if(hours < lmax - 0.75)
laying = false;
else if(hours > lmin + 0.5)
laying = true;
Chickens will vary in egg production during their lifetimes. Here is the probability of laying an egg (for a chicken in laying state) based on different ages:
- Less than 120 days old: 0% chance
- Less than 3 years old: 80% chance
- Less than 5 years old: 50% chance
- Older: 5% chance
Once your simulation is complete, compare all 4 management strategies. Note that in the real world, breed, nutrition, and many other things also make a difference. However, these are two of the major factors that affect backyard egg production.
Turning in the Project
Upload your completed project here. Name your file with your first and last name, like this: lastname_firstname_p2.cpp. So I would name project 2 long_seth_p2.cpp.