Now, I think you are quiet comfortable with basics of link list.lets start the actual coding part of our project.
As we are designing a Family tree,We need Following two things:
1)Data of family tree
2)Functions that will process different operations on Family tree
now lets understand about how we are going to take Family tree from user.
1)We can take information for each person in family such as name,age,Gender,etc.
2)We need a two pointers for every person that will point sibling and child.
The way in which we are going to store the data is shown below:
struct node
{
char name[50];
short int age,x; // x - height of node
bool g; // g- gender
node* fc; // Pointer to first child
node* ns; // Pointer to next sibling
node();
void getData();
};
void node::getData()
{
char ch;
cout<<"\nName of the Person: ";
cin>>name;
cout<<"Age of "<<name<<": ";
cin>>age;
cout<<name<<" is (m/f): ";
cin>>ch;
if(ch=='m')
g=1;
}
Now,after taking the personal information,we need to make connection of this node in family according to relationship..
So we will ask the user to enter the relation of this person with specific person in family tree and then we will connect these two node depending on the relationship.i.e sibling or child.
void familyTree::addNew()
{
node* temp = new node;
temp->getData();
if(start == NULL)
{
start = temp;
temp->x=0;
}
else
{
cout<<"\nEnter any relation's name: ";
char name[50];
cin>>name;
cout<<"\n1. Child\n2. Sibiling\n\n"<< temp->name <<" is ____ to "<<name<<" : ";
int opt;
cin>>opt;
switch(opt)
{
case 1:
addChild(search(name),temp);
break;
case 2:
addSib(search(name),temp);
break;
}
}
cout<<"\nPerson sucessfully added.\n";
}
As we are designing a Family tree,We need Following two things:
1)Data of family tree
2)Functions that will process different operations on Family tree
now lets understand about how we are going to take Family tree from user.
1)We can take information for each person in family such as name,age,Gender,etc.
2)We need a two pointers for every person that will point sibling and child.
The way in which we are going to store the data is shown below:
For the above implementation we need a structure which will consist of name,age ,gender and we will require two pointers to point sibling and child.
struct node
{
char name[50];
short int age,x; // x - height of node
bool g; // g- gender
node* fc; // Pointer to first child
node* ns; // Pointer to next sibling
node();
void getData();
};
void node::getData()
{
char ch;
cout<<"\nName of the Person: ";
cin>>name;
cout<<"Age of "<<name<<": ";
cin>>age;
cout<<name<<" is (m/f): ";
cin>>ch;
if(ch=='m')
g=1;
}
Now,after taking the personal information,we need to make connection of this node in family according to relationship..
So we will ask the user to enter the relation of this person with specific person in family tree and then we will connect these two node depending on the relationship.i.e sibling or child.
Given below is addNew() method which will add a new person according to relation with previous members in Family tree.
void familyTree::addNew()
{
node* temp = new node;
temp->getData();
if(start == NULL)
{
start = temp;
temp->x=0;
}
else
{
cout<<"\nEnter any relation's name: ";
char name[50];
cin>>name;
cout<<"\n1. Child\n2. Sibiling\n\n"<< temp->name <<" is ____ to "<<name<<" : ";
int opt;
cin>>opt;
switch(opt)
{
case 1:
addChild(search(name),temp);
break;
case 2:
addSib(search(name),temp);
break;
}
}
cout<<"\nPerson sucessfully added.\n";
}
good work team๐
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood work!
ReplyDeleteGreat Work
ReplyDeletethank you so much
DeleteBinary Tree for Family Tree!!
ReplyDeleteYuss
DeleteInformative post !
ReplyDeletethank you
ReplyDeletethank you so much
ReplyDeleteGreat work team ๐ฏ๐ฏ๐ฏ๐ฏ keep it up๐ฅ๐ฅ๐ฅ
ReplyDeleteGood
ReplyDeleteNice work
ReplyDeletethanks
DeleteSuperb
ReplyDeleteGood implementation
ReplyDeletethanks
DeletePerfectly written!
ReplyDeleteVery nicely implemented.. excellent job..keep it up ๐
ReplyDelete