Thursday, April 16, 2020

TAKING THE FAMILY TREE DATA FROM USER

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:

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";
}




19 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Great work team ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ๐ŸŽฏ keep it up๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ

    ReplyDelete
  3. Very nicely implemented.. excellent job..keep it up ๐Ÿ‘

    ReplyDelete

DOCUMENTATION

Course project Title:      Implementation of Family tree Using Generalized Link List Description:    In this project we have create...