Use a Linked List?
Hi, I was given the task of making...almost like a family tree sort of program..for example..
i have a Person Object, well in this person object, it should have...
object person
{
father;
mother;
number of children; (then pointers or somethign to every child)
number of wives; (pointers to every wife)
id number;
lot number;
date born;
date died;
}
and i need to be able to add children at any time, and able to wives or change things and whatnot..and like in the program, if I were to click on like father..it would take me to his person structure and display all his information....I thought that I should just use class objects with link lists connecting them..
just checking with you guys to see if that would be the way to go...
but the problem kinda comes in if this person decides to have another child..how do i just make up another child at runtime?
sorry for the complete sloppiness, hope i got my message across of what i''m trying to do
thank you
Yes, declare your child pointer as a list (i think lists are more appropriate in this case) of person*, and you should be good to go.
Could also use double pointers - person **children.
Could also use double pointers - person **children.
quote:
..how do i just make up another child at runtime?
Did you ask your girlfriend/wife ?
Aside from that, more than using the STL containers vector or list, you have a simple problem of database modelization. Did you have any course in database modelization ? Have you checked the MERISE method ?
There are here some key definitions to coin up before implementing structs:
- a wife, a husband, a child are persons.
- a person has a first names, a last name, a birth date and a death date.
- a person is the child of two other distinct persons.
- a person can be married with one other person. This relation holds a wedding date and an end date (divorce or death of one of the persons).
Looking from these definitions and applying the MERISE method will get you the needed structs and define the needed algorithms to derive the functionalities you need.
Hope that helps.
Ghostly yours,
Red.
You could almost use an extended binary tree where instead of just a left and right pointer within each node you could have a list/array of pointers that would point to the descendants.
Looking through the answers, I wonder how people manage both occurences and keep a log of changes in the family:
- wedding between two divorced people and already having children.
- adoption of a new child by parents and trying to relate this adopted child to the old and new parents.
I find the design faulty at the light of these two cases.
If you don''t have any of these two cases, then the design''s enough to get by.
Ghostly yours,
Red.
- wedding between two divorced people and already having children.
- adoption of a new child by parents and trying to relate this adopted child to the old and new parents.
I find the design faulty at the light of these two cases.
If you don''t have any of these two cases, then the design''s enough to get by.
Ghostly yours,
Red.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement