Noah's Ark!

Hello, everyone! I'm so sorry to bother you guys with this, but I really need assistance.
I have an assignment about Noah's Ark and I really don't get it. Here it is:

"The Noah's Ark Inventory Application
The scenario is this: you are on Noah's ark with a set of animals. As the months
pass, the animals begin to breed. You need to keep track of your animal
inventory down below.
The ark has 3 types of animals: mammals, birds, and fish.
Your program should have at least:
2 kinds of mammals (e.g. cat, dog),
2 kinds of fish (e.g. goldfish, shark), and
2 kinds of birds (e.g. eagle, parakeet).
You should start the program with 2 animals of each species on the ark, one
male and one female, for a total of 12 animals.
The program should give you a menu such as follows:
You have been on the ark for 11 months. Would you like to:
1 - Let another month pass
2 - Check inventory
3 - Quit
If you let another month pass, all of the animals on the ark are aged by a month.
Each female animal in heat gives birth to another animal of the same species.
You will then get the same menu:
You have been on the ark for 12 months. Would you like to:
1 - Let another month pass
2 - Check inventory
3 - Quit
If you hit 2, you should see something like this:
Animal #1: I am a female cat, 12 months old
Animal #2: I am a male cat, 12 months old
Animal #3: I am a male cat, 0 months old
Animal #4 I am a male shark, 12 months old
Animal #5: I am a female shark, 12 months old
Animal #6: I am a male shark, 6 months old
.........
All female mammals give birth once every 12 months. All female fish give birth once every 6
months. All female birds give birth once every 9 months."

I kind of have an idea of what to do like I need array's, class names and a submenu, but I don't know how to start it.
Can somebody please open my mind on how to get it started, or give me hints on how to create a solution?
I went for tutoring and the tutor couldn't help me.
Thank you in advance, any idea is welcomed.
Last edited on
Thus, each Animal has three properties: gender, type, and age. The Animal could have methods, like
1
2
3
4
void age();
void print() const;  // OR: ostream & operator<< ( ostream &, const Animal & );
bool heat() const;
Animal breed() const;

The last two naturally:
1
2
3
4
if ( a.heat() ) {
  auto puppy = a.breed();
  // use puppy
}
Start by defining an Animal class. That will allow you to define the attributes for each animal.

In addition to what keskiverto suggested, keep in mind that female animals have two additional attributes, how often they come in heat, and the last month when they were in heat.

You probably want to use a std::vector<Animal> to keep track of your animals. vectors resize automatically, they also keep track of how many entries you have, and you don't have to worry about overflowing an array.
Last edited on
I would not give females anything "more". The "how often" is calculable from type and "when last" ... Fibonacci bunnies do it at certain age(s) without remembering the past. Furthermore, it is ok to check whether a male is in heat. Who knows, they could some month say "yes".

However, I did forgot one (text) attribute: kind.


A more complex simulation would handle also dying from old age, being eaten by predator, and check whether there are any males of the species left (for those species whose females need a male for the breed function).
I see, but excuse my dumbness here, how would I do for it to add the baby after both parents?
I have tried it only with dogs, as I want to do one animal at a time. The puppy adds at the beginning of the list, instead of after both parents.
The puppy adds at the beginning of the list,

Since you haven't shown your code, we can't answer that question.

Did you use a vector as previously suggested? If you did, it would simply be:
1
2
3
4
5
6
7
  vector<Animal>  animals;
...
  // iterate through all the animals in the vector
  if (animals[i].inHeat())
  {  Animal offspring (animals[i].get_kind(), gender);
      animals.push_back (offspring);
  }



Oh yeah, I totally forgot to include my code, sorry about that.
But, on the bright side, your help was extremely useful! without you guys I really couldn't have done it.
Thank you!
Topic archived. No new replies allowed.