Graduation exercise from cplusplus.com
Members - Reputation: 107
Posted 11 August 2012 - 10:53 AM
So, I was doing some simple C++ exercises the other day and I found a very interesting one I'd like to complete.
(scroll down to the last exercise called Graduation).
It is as difficult as it is fun and it might be too early for me, but I'd still like to attempt it.
I realize that I first need to create a struct that will hold all the properties of bunnies such as sex/name/age.
What do I do next? How can I loop through the created instances of this struct? Every turn, I have to check if a bunny is too old/ready to procreate/whatever, and so aren't I supposed to have some kind of way to loop through the list of existing instances in the same way as I'd do it with an array? If not, then what am I missing?
I'm not asking for a walkthrough here. Just general tips on how to get started.
Thanks in advance!
Members - Reputation: 502
Posted 11 August 2012 - 12:15 PM
With an array you could jump to any position of that array, however a link list you must start at the beginning node and transverse through each node in order to reach the desired node. Each node will have a pointer to next node and a structure/pointer to the data it contains.
Start by laying out the framework of the application.
Main Initialization Main Loop User Input Bunny Update Loop Change State Create New Bunnies Kill Current Bunny Mass Murder Bunnies Sort Bunny by Age Display Output File Output Cleanup Exit
I have noticed that advanced classes is part of the requirements for the exercise. A class CBunny would be good candidate for this instead of a struct. For the link list, pass a pointer of CBunny as the data.
Good Luck ;)
Edited by Neometron, 11 August 2012 - 12:17 PM.