Question: This is in C not C++ Here is the given code. Please write the addRear, printLegal, and getAge functions #include #include #include typedef struct person

 This is in C not C++ Here is the given code.

This is in C not C++

Here is the given code. Please write the addRear, printLegal, and getAge functions

#include  #include  #include  typedef struct person { char *name; int age; struct person *next; } Person; void print(Person *); // prints the entire list Person *addFront(Person *, char *, int);// adds a new node to the front of the list Person *addRear(Person *, char *, int); // adds a new node to the end of the list void printLegal(Person *); // prints the names who are 21 or older int getAge(Person *, char *); // returns age of the name specified (or -1) int main(void) { char input1[100]; int input2; Person *myList = NULL; printf("Enter a person's name (one word) and age : "); scanf("%s %d", input1, &input2); while (input2 != 0) { if (input2 > 20) myList = addRear(myList, input1, input2); else myList = addFront(myList, input1, input2); printf("Enter a name (one word) and age, enter 'xxx' and 0 to exit : "); scanf("%s %d", input1, &input2); } printf(" "); print(myList); printf(" "); printLegal(myList); printf(" Enter the name of a person to look up their age : "); scanf("%s", input1); while ( strcmp(input1, "xxx") != 0 ) { printf("\t%s is %d years old ", input1, getAge(myList, input1) ); printf("Enter a name to look up their age or 'xxx' to exit : "); scanf("%s", input1); } return 0; } void print(Person *ptr) { printf("The list is : "); while (ptr) { printf("[%s-%d] ", ptr->name, ptr->age); ptr = ptr->next; } printf(" "); return; } Person *addFront(Person *ptr, char *n, int a) { Person *newNode = malloc( sizeof(Person) ); newNode->name = malloc( strlen(n) + 1 ); strcpy(newNode->name, n); newNode->age = a; newNode->next = ptr; return newNode; } 

This lab maintains a linked list of people, where each node contains a name (one-word names only) and the age of that person. For example, a node might contain "BigA1" and 21The program operates as follows .Prompts the user for names and ages, building the list with calls to addFront and addRear Pnnts the entire list, and then pnnts only the people in the list who are 21 or older .Prompts the user for a name, and then prints the age of that person (if they are in the list) The code below is on Blackboard. Write the three functions addRear,printlegal and getAge. snclude includo #include typedef struct person ( char nana int aga struct person "next Person; void print (Person Person addFront (Person , char, int): Person addRoar (Person", char*, int) void printLegal(Person ); int getAge (Person , char) // prints the antire list /l adds a new node to the front of the list // adds a new node to the and of the list // prints tho names who are 21 or older // returns age of the nane specified (or -1) int main (void) char inputi[100] int input2 Person tayList NULL printf ("Enter a person's nane (one word) and age") scanf ("is %d", input1, 'input2); while (input20) if (input2 20) alse printf ("Enter a name (one word) and age, enter 'xxx' and o to exit " myList mylist addRear (myLiat, inputi, input2): addFront (myList, inputl, input2) scanf ("s d,inputl, sinput2) printf ("In ") print (myList) printf ("nln"): printLegal (nyList) printf ("n nEnter the nane of a person to look up their age") scanf ("%s", input1) while stremp (inputi, "xxx") 0) printf (" \ t%s s td years oldn", input1, getAge (myList, input1 ) ); printf("Enter a name to look up their age or 'xxx ' to exit : "); scanf("%s", input1); return 0: void print (Person ptr) printf ("The list is ") while (ptr) { printf("[%s ptr->age); ptr } = -8d] "' ptr->name , ptr->next; printt ("In") return; Person addFront (Person ptr, char *n, int a) t Person neNode malloc( sizeof (Person) newNode->name malloc ( strlen (n) + 1 ) ; strepy (newNode-name, n): newNode->age = a; newNode->next = ptr ; return newNode

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!