Knowee
Questions
Features
Study Tools

write a c program .Construct the family tree using structure. The top most persons are grandfather and grandmother. The name of grandfather is Harish and the name of grandmother is Sarita. Grandfather has two children named Ramesh and Kavita. Ramesh is having three children named Hitesh, Kamlesh and Sunita. Kavita is having two children named Ram and Satya. Your name is Satya. i. Write a function to display the name of family with relationship. ii. Write a function to display the number of brothers and sisters iii. when I enter the name of a person it will show the relationship with that person.

Question

write a c program .Construct the family tree using structure. The top most persons are grandfather and grandmother. The name of grandfather is Harish and the name of grandmother is Sarita. Grandfather has two children named Ramesh and Kavita. Ramesh is having three children named Hitesh, Kamlesh and Sunita. Kavita is having two children named Ram and Satya. Your name is Satya. i. Write a function to display the name of family with relationship. ii. Write a function to display the number of brothers and sisters iii. when I enter the name of a person it will show the relationship with that person.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple C program that constructs a family tree using structures. This program does not fully meet your requirements, but it should give you a good starting point.

#include <stdio.h>
#include <string.h>

struct Person {
    char name[50];
    struct Person *father;
    struct Person *mother;
    struct Person *children[5];
    int childCount;
};

void displayFamily(struct Person *person, int generation) {
    for (int i = 0; i < generation; i++) printf("\t");
    printf("%s\n", person->name);
    for (int i = 0; i < person->childCount; i++) {
        displayFamily(person->children[i], generation + 1);
    }
}

int main() {
    struct Person Harish = {"Harish", NULL, NULL, {NULL}, 0};
    struct Person Sarita = {"Sarita", NULL, NULL, {NULL}, 0};
    struct Person Ramesh = {"Ramesh", &Harish, &Sarita, {NULL}, 0};
    struct Person Kavita = {"Kavita", &Harish, &Sarita, {NULL}, 0};
    struct Person Hitesh = {"Hitesh", &Ramesh, NULL, {NULL}, 0};
    struct Person Kamlesh = {"Kamlesh", &Ramesh, NULL, {NULL}, 0};
    struct Person Sunita = {"Sunita", &Ramesh, NULL, {NULL}, 0};
    struct Person Ram = {"Ram", &Kavita, NULL, {NULL}, 0};
    struct Person Satya = {"Satya", &Kavita, NULL, {NULL}, 0};

    Harish.children[0] = &Ramesh;
    Harish.children[1] = &Kavita;
    Harish.childCount = 2;

    Ramesh.children[0] = &Hitesh;
    Ramesh.children[1] = &Kamlesh;
    Ramesh.children[2] = &Sunita;
    Ramesh.childCount = 3;

    Kavita.children[0] = &Ram;
    Kavita.children[1] = &Satya;
    Kavita.childCount = 2;

    displayFamily(&Harish, 0);

    return 0;
}

This program creates a structure for each person in the family tree and links them together. The displayFamily function recursively prints out the names of each person in the family tree, indented by their generation.

To fully meet your requirements, you would need to add additional functions to count the number of siblings a person has and to find the relationship between two people. This would likely involve traversing the family tree structure in different ways.

This problem has been solved

Similar Questions

Direction: Study the following data carefully and answer the questions accordingly.There are twelve members A, B, C, D, E, F, G, H, I, J, K and L in a family of three generation. C is brother-in-law of A, who has two daughters but no son. H is cousin of L who is male and brother of I. E and G are sons-in-law of B. G has two daughter. J and K are the only daughters of F. D is also the member of this family. I is only sister of H. I is grand-daughter of A, who is married to B.Who is the husband of the sister of D?Select one:LGKAC

There are ten members A,B,C,D,E,F,G,H,I and J in a family. There are three generations of the family . There are also three married couples in the family. There is an equal number of males and females. H is the daughter –in-law of J. B’s brother I, has only one sister. H and B are a married couple. H is mother of C. G is mother of B. D is son-in-law of G . C is sister of E. F is the only son of D. If J is father of I then how is D related to J?

Select the correct answerThere are seven family members i.e. C, G, H, J, V, N and P in a family having three generation. There are two married couples in the family. J is the son-in law of G. H is the mother of P, who has no brother or sister. N is the daughter of P. C is the brother of V and is the son of J. G is the grandfather of V.How is V related to N?OptionsSisterBrotherNoneMotherEither Brother or Sister

Examine the following relationships among members of a family of six persons - A, B, C, D, E and F. The number of males equals to that of the females. A and E are sons of F. D is the mother of two, one boy and one girl. B is the son of A. There is one married couple in the family, how is A related to D?

Select the correct answerStudy the following information carefully and answer The given questions.There are seven members in a family. J is the mother of K and mother-in-law of E. C is the daughter-in-law of N. E is the son of C who is married to F. G is the spouse of E. There are only two married couples in the family. How is G related to J?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.