Saturday, May 22, 2010

C/C++ programming...need help?

I need some ideas to solve a problem with binary trees in C. I have to build a binary family tree and I am given relations between relatives. For example: Matilde is grand-grand-mother/grand-grand-father for Agnes. Julia is sibling for Mark. Paul is father for Dan and Ana. And so on. How should I do this? I thought about starting putting people in the tree as soon as I read a sentence. But I think I will complicate myself a lot. I mean, after the first three sentences I know relations between Matilde and Agnes, Julia and Mark, Paul, Dan and Ana. But nothing for Matilde and Paul for ex.. So...how should I do it?

C/C++ programming...need help?
The CS Library at Stanford has a good tutorial. have a look. They are not really all that hard.
Reply:frst of all data structure concept shd be clear to u befr programming
Reply:Does not look easy. May be you can post the question at websites like http://homeworkhelp.co.in/ as well.
Reply:Not sure what exactly you have in mind, but here are some random ideas.





1. If you are trying to deduce family relationships from some given information, you might want to look into logic programming languages like prolog.





http://www.perl.com/lpt/a/967





All you need to do is to define some rules and enter the relationships between people.


For example, the following rule determines if two people are


cousins.





is_cousin(Person, Cousin)


:- is_parent(X, Person),


is_parent(Y, Cousin),


is_sibling(X, Y).





If there exists a person "X" who happens to be the parent of "Person", and there exists a person "Y" who happens to be the parent of "Cousin", and "X" and "Y" are siblings, "Person" and "Cousin" must be cousins.








2. If you are trying to use C/C++ to build family relationships,


you can use the following data structure.





struct Person {


std::string name;


Person *father, *mother;


std::vector%26lt;Person*%26gt; children;


};





The following function returns true if "a" and "b" are siblings.





bool isSibling(Person* a, Person* b) {


return (a-%26gt;father == b-%26gt;father || a-%26gt;mother == b-%26gt;mother);


}


No comments:

Post a Comment