Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following struct definition, which could be a useful way of representing a family relationship: typedef struct person _ s { char name [
Consider the following struct definition, which could be a useful way of representing a family relationship:
typedef struct persons
char nameMAXNAME;
int personid;
struct persons mother;
struct persons father;
person;
Here we have defined a struct named person, that includes, as part of its definition, pointers to other person variables representing a mother and father, respectively. With this syntax, we have to be careful whether we are accessing a variable of the struct type or a pointer to a variable of the struct type, as the following example illustrates:
person myperson;
person personptr;
myperson is a struct variable so we use the operator
printfs
myperson.name;
myperson.mother is a pointer to a person, so we use operator
printfs
myperson.mothername;
personptr is a pointer, so we use the operator
printfs
personptrname;
personptrmother is a pointer to a person, so we use the syntax
printfs
personptrmothername;
STOP: Do not proceed on this program until the code sample above makes sense to you. Ask questions now before diving in
This type of person struct, with relationships between, spouses, children, and parents, can be a useful way to represent a family tree. Included in subdirectory trees are four different GEDCOM files, which are a standardized way of encoding genealogical information. There's a lot of this format we can skip for our purposes, so let's review a small subset of some of the syntax of file treesbronteged:
@I@ INDI
NAME Patrick Bronte
@I@ INDI
NAME Maria Branwell
@F@ FAM
HUSB @I@
WIFE @I@
CHIL @I@
CHIL @I@
CHIL @I@
CHIL @I@
CHIL @I@
CHIL @I@
@F@ FAM
HUSB @I@
WIFE @I@
CHIL @I@
CHIL @I@
We can deduce some of the features of this file format, and craft our struct and family tree program accordingly:
Each person is given an ID number based on the sequence @I@ @I@ etc. We should be able to scanf for this.
We can look for the "family" definitions to link the people together: Maria Branwell @I@ is the wife of Patrick Bronte @I@ and is the child of @I@
Write a program that uses pointers within structures to build a family tree from a userspecified GEDCOM file. Once the GEDCOM file is parsed, prompt the user for an ID number, and provide the direct family tree parents spouses, and children for that person.
Your program should match the following examples, as well as the included test cases:
Enter the name of the Genealogy file to analyze: treesbronteged
Processing file treesbronteged...done! Found people and families.
Enter the ID for the person to display:
Person ID :
Name: Charlotte Bronte
Parents: known
Father: Patrick BronteID
Mother: Maria BranwellID
Spouses: known
Spouse : Arthur Bell NichollsID
Children: known
Enter the name of the Genealogy file to analyze: treesroyalged
Processing file treesroyalged...done! Found people and families.
Enter the ID for the person to display:
Person ID :
Name: ElizabethII Alexandra MaryWindsor
Parents: known
Father: GeorgeVI WindsorID
Mother: Elizabeth Angela MargueriteBowesLyonID
Spouses: known
Spouse : Philip MountbattenID
Children: known
Child : Charles Philip ArthurWindsorID
Child : Anne Elizabeth AliceWindsorID
Child : Andrew Albert ChristianWindsorID
Child : Edward Anthony RichardWindsorID
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started