logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

Rashmi AgnihotriComputer science

753 Answers

Hire Me
StatAnalytica ExpertGeneral article writing

907 Answers

Hire Me
Samuel BarberaMathematics

819 Answers

Hire Me
Neha SharmaaStatistics

1156 Answers

Hire Me
C Programming

you will create a struct person and use it to create a struct node so that you can store a linked list of persons.


The goal of this assignment is threefold: work with structs, work with linked lists, implement a “database-like” program that stores records that can be queried. Specifically, in this assignment, you will create a struct person and use it to create a struct node so that you can store a linked list of persons. You will then create a struct family and finally an array of struct family. A single struct family will store individual person structs in a linked list. You will implement various linked list functions and some other functions (described later).

A person will consist of:

  • first name (string (no more than 10 chars))
  • age (int)
  • sex (char)

A node will consist of:

  • a person struct
  • a next pointer (struct node *)

Assume that the struct person member has the name me (as used below).

A family will consist of

  • a last name (string (no more than 12 chars))
  • size (int) (number of people in the family, or the number of structs currently in the linked list)
  • a pointer to the front of the linked list of family members (struct node *)

You will create an array of your struct family, e.g., struct family families[10]; You will need no more than 10 array elements. To access a family, use families[i]. To access the linked list, use families[i].front. Given a struct node *temp, which is a node in a linked list, access that person’s name, age and sex using temp->me.first, temp->me.age, temp->me.sex. You are free to name your structs, members and array variable anything you like, the examples here are just to help you understand the structure of these three struct types and how to access into them.

Your program may consist of a single file or multiple files, your choice. You may but do not need a header file. Either way, make sure you comment your function prototypes! Your struct definitions should either be at the top of your single .c file if you only have one or in your .h file if you choose to use a header file. NOTE: define the structs in the order listed above because person is used in node and node is used in family.

Aside from main, you will need the following functions (at a minimum):

  • input – input a person’s data from disk
  • findFamily – given a person’s last name, determine the index i in the families array that matches that last name, or use a special value if that family does not yet exist (I use -1).
  • insertPerson – insert a new person (first name, age, sex) into families[i]. This is an ordered insert based on first name. This function should receive families[i].front (the pointer to this family’s linked list), and the new person’s first name, age and Allocate

a new node, copy into this node the person’s first name, age, sex, and insert the node into the linked list, returning a node pointer to the front of the list (needed when inserting into an empty list or at the front of a list).

  • outputFamily – receives a family’s front pointer (e.g., families[i].front) and the family’s last name (e.g., families[i].last) and outputs the family’s last name and then the first names of each person in the family; this is a traversal function to print out the elements of a linked list but only prints first names, not ages or
  • destroy – a function which receives the entire array of families and n (the number of families in the array), and destroys each family’s linked list, resetting each families[i].size to 0 and families[i].front to NULL
  • ageSearch – receives the front pointer of a family (families[i].front), last name (families[i].last) and an int (an age) and finds and outputs the first and last name of all people in the given linked list who are of the given
  • smallestLargest – receives the entire array of families and n, and determines the two families who have the least and most people, outputting those families, calling upon the outputFamily function to actually output the smallest and largest families. If two families have the same size, say families[i] and families[j], then output the one with the smaller index. That is, when searching, if families[i].size == families[firstfound].size then we ignore families[i].

You may write other functions if or as needed.

In main, declare your array of struct family elements (no more than 10 are needed). Declare the array statically (do not use a pointer/calloc), and declare any variables you need. Initialize your array of family elements by setting each element’s size to 0 and front pointer to NULL. You do not need to initialize the last names but if you do make sure you assign them using strcpy, not = as in strcpy(families[i].last, “”); Next in main, use a while loop to iterate through the contents of the input file until you reach EOF. This might look like what you implemented in program 2, for instance while(getInput(…)!=EOF) {…} or you can test for feof. The input function will need to input one row of the input text file which will consist of a first name, last name, age and sex.

  • Call the findFamily function to locate the array index in families that is currently storing the given last name, if there is one. In my program, findFamily returned -1 if no such family was
  • If there was no family, then you will add a new array element to families as follows:
    • assume n is the current number of families, then families[n] is the first unused array location. Set families[n].size to 1, set families[n].last to the last name as input (using strcpy), and call your insert function passing families[n].front. Remember that insert will return a front pointer, so this should be part of an assignment statement. Finally, increment
    • if a family was found, call insert passing it the new person info and that array element’s front pointer (e.g., families[location].front = insert(families[location.front], …) where … are the parameters for the new person. Finally, add 1 to that family’s
  • The insert function will be an ordered insert based on first name. Remember to implement the three cases (empty list, inserting at the front, inserting elsewhere). You will have to malloc a new node. If that node is called temp, to assign temp its first name, age and sex, the code will look something like this:

strcpy(temp->me.first, first); temp->me.age=age;


After exiting the while loop having inserted all new people into an appropriate linked list, do the following. Make sure you close the input file when done with it

Use a for-loop to iterate through all n families and print out all of the families using your outputFamily     function.    This function receives families[i].front and families[i].lastName so that the function can print out the family’s last name and then each first name in the linked list.


After the for-loop, prompt the user to enter an age (I’m calling it inputAge). Use a while loop that iterates while inputAge > 0. Search all of the families for anyone whose age is equal to the input age and output that person’s first and last names. This requires a for-loop inside the while loop to iterate through all n families, passing inputAge, families[i].lastName and families[i].front to the ageSearch function. If a family member is found for the given age, output that person’s first and last name. This while loop ends with another input for the next inputAge value. Upon entering 0 (or negative), exit the loop


Next, call the smallestLargest function, passing it the entire families array and n. This function locates and outputs the entire family information for the smallest family and the largest family. Make sure you output which is which.

Finally, pass to a destroy function the families array and n. This function uses a for-loop to iterate through each family[i] and an inner while loop to iterate through each node of this family’s linked list, freeing each node. After destroying a linked list, reset families[i].size to 0 and families.lastName to “” (again, using strcpy).

Run your program on the two data files on the website. An example of output from the first run is shown below. To fully test yours, use for inputAge these values: 53, 29, 57, 54 and 0.


Printing all families

Howe family: Dylan, Georgia, Janet, Steve, Virgil, Underwood family: Ian, Ruth,

Zappa family: Diva, Dweezil, Frank, Gail, Moon, Wakeman family: Jemma, Oliver, Rachel, Rick, Hackett family:       Jo, John, Steve,

Enter an age to search for: 53 Searching for all people of age 53:

Frank Zappa, Rachel Wakeman,

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

419 Experts Online