Answered step by step
Verified Expert Solution
Link Copied!

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 person_s {
char name[MAX_NAME];
int person_id;
struct person_s *mother;
struct person_s *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 my_person;
person *person_ptr;
...
// my_person is a struct variable so we use the '.' operator
printf("%s
", my_person.name);
// my_person.mother is a pointer to a person, so we use '->' operator
printf("%s
", my_person.mother->name);
// person_ptr is a pointer, so we use the '->' operator
printf("%s
", person_ptr->name);
// person_ptr->mother is a pointer to a person, so we use the '->' syntax
printf("%s
", person_ptr->mother->name);
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 sub-directory 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 trees/bronte.ged:
0 @I0001@ INDI
1 NAME Patrick /Bronte/
...
0 @I0002@ INDI
1 NAME Maria /Branwell/
...
0 @F001@ FAM
1 HUSB @I0001@
1 WIFE @I0002@
1 CHIL @I0003@
1 CHIL @I0004@
1 CHIL @I0005@
1 CHIL @I0006@
1 CHIL @I0007@
1 CHIL @I0008@
...
0 @F004@ FAM
1 HUSB @I0013@
1 WIFE @I0012@
1 CHIL @I0002@
1 CHIL @I0014@
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 @I0001@, @I0002@, etc. We should be able to scanf() for this.
We can look for the "family" definitions to link the people together: Maria Branwell (@I0002@) is the wife of Patrick Bronte (@I0001@), and is the child of @I0013@.
Write a program that uses pointers within structures to build a family tree from a user-specified 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: trees/bronte.ged
Processing file trees/bronte.ged...done! Found 14 people and 4 families.
Enter the ID for the person to display: 5
Person ID 5:
Name: Charlotte /Bronte/
Parents: 2 known
Father: Patrick /Bronte/(ID 1)
Mother: Maria /Branwell/(ID 2)
Spouses: 1 known
Spouse 1: Arthur Bell /Nicholls/(ID 9)
Children: 0 known
Enter the name of the Genealogy file to analyze: trees/royal92.ged
Processing file trees/royal92.ged...done! Found 3010 people and 1422 families.
Enter the ID for the person to display: 52
Person ID 52:
Name: Elizabeth_II Alexandra Mary/Windsor/
Parents: 2 known
Father: George_VI /Windsor/(ID 32)
Mother: Elizabeth Angela Marguerite/Bowes-Lyon/(ID 51)
Spouses: 1 known
Spouse 1: Philip /Mountbatten/(ID 57)
Children: 4 known
Child 1: Charles Philip Arthur/Windsor/(ID 58)
Child 2: Anne Elizabeth Alice/Windsor/(ID 59)
Child 3: Andrew Albert Christian/Windsor/(ID 60)
Child 4: Edward Anthony Richard/Windsor/(ID 61)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

5. Identify the logical fallacies, deceptive forms of reasoning

Answered: 1 week ago

Question

6. Choose an appropriate organizational strategy for your speech

Answered: 1 week ago