Hands-On C++
If you are in this class, you should have some familiarity with C++ already. This is not intended to serve as an intro to C++, but a reminder of some quirks and features of C++.
In your groups, create a C++ class for an Organism
. G
- Give it three simple attributes: an integer to represent its age called
age
, a string to represent its name calledname
, and a boolean value to represent whether it is alive or dead calledisAlive
. - Create a comparison operator overload to allow you to sort organisms by age.
Create a second C++ class called Population
.
- Give it two attributes: a vector called
pop
which is a vector ofOrganism
s, and an integermaxSize
which is the maximum size of the population. You can set this max size to your preferred value. - Instantiate a default population of 20 organisms with random ages.
- Sort the population using
std::sort
.
You have the entire class period from now until the end of class with your groups to work on this, and you are free to look up information online, go back through old notes, ask for help; whatever you need to do to recall how to create new classes and work with them.