The goal of this lab is to practice working with pointers and dynamic memory. It also reviews linked lists, putting them now in the context of C. Quite a bit of the program is written for you; you need to add some parts that have to do with structs and dynamic allocation of memory.
Suppose we are interested in dropping 300 19-year-olds onto an isolated island and observing the growth and other trends of the population over the course of 500 years, experimenting with various constraints on how the society they form works. Since time, cost, and ethics prevent us from running these experiments on real people, we will simulate this scenario in a computer program.
We will model the population and the people in the population with a collection of objects. For every "year" of the experiment, certain individuals of the population will give birth to new individuals, certain individuals will get married, and certain individuals will die. In this way the population will change over time (hopefully grow), and these things depend on rates of marriage, birth, and death. (We are assuming only married females give birth, and there is no divorce, though there is the possibility of remarriage if a spouse dies. Also, an individual must have lived a certain number of years before becoming eligible for marriage.)
The experiment this program performs in particular is tracing surnames. The population begins with 60 surnames represented equally. At the end of 500 years, how many surnames have died out, how many people have each surname, and what are the relative proportions of males and females for each surname?
We have the following parameter values (which could be changed, but this seems to represent a "sweet spot", avoiding having the population either dwindle or explode):
The entire population is modeled by a personList
.
We populate it initially with 300 people, 5 for each of the
60 available surnames.
Since we are going to start the simulation at year 0,
we give each of them a birth year of -19.
There will be a program population.c
that drives the simulation.
This will use the following structs:
person
, used to mode an individual in the
simulation.
personList
, a linked list representing a set of
people.
personNode
, a node in such a linked list, having
a person
as the datum.
Your task will be to fill in some of the code for these. Then you will make a modification to the simulation experiment and run it.