Question: Given: contacts2.c #include #include #include #include struct node { struct contact *element; struct node *next; }; struct contact { char name[30]; int phone; char email[30];

![*element; struct node *next; }; struct contact { char name[30]; int phone;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5b49c16f69_58766f5b49b7e76b.jpg)
![char email[30]; }; struct node *front = NULL; int count = 0;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f5b49ce25da_58866f5b49c55aea.jpg)
Given: contacts2.c
#include
#include
#include
#include
struct node {
struct contact *element;
struct node *next;
};
struct contact {
char name[30];
int phone;
char email[30];
};
struct node *front = NULL;
int count = 0;
void branching(char c);
int insertion();
void search();
void delete();
void printall();
main() {
char ch = 'i';
while (ch != 'q') {
printf("Enter your selection ");
printf(" i: insert a new entry ");
printf(" d: delete an entry ");
printf(" s: search an entry ");
printf(" p: print all entries ");
printf(" q: quit ");
scanf(" %c",&ch);
branching(ch);
}
}
void branching(char c) { // branch to different tasks
switch(c) {
case 'i': insertion(); break;
case 's': search(); break;
case 'd': delete(); break;
case 'p': printall(); break;
case 'q': break;
default : printf("Invalid input %d ", c); break;
}
}
int insertion() { // insert a new entry at the front
struct contact *c = (struct contact *) malloc(sizeof(struct
contact));
printf("Enter name, phone, email: ");
scanf("%s", c->name);
scanf("%d", &(c->phone));
scanf("%s", c->email);
struct node *n = (struct node *) malloc(sizeof(struct node));
n->element = c;
n->next = front;
front = n;
count++;
printf("The number of entries = %d ", count);
return 0;
}
void search() { // print phone and email via name
char sname[30];
int i;
struct node *retval;
printf("please enter the name to be searched for: ");
scanf("%s", sname); //sname is an array, no &
struct node *n;
for (n = front, retval = NULL; n != NULL; retval = n, n = n->next) {
if (strcmp(sname, n->element->name) == 0) {
printf("phone = %d ", n->element->phone);
printf("email = %s ", n->element->email);
}
}
printf("The name does not exist. ");
}
void delete() {
struct node *prev;
struct node *n;
int found = 0;
char sname[30];
int i;
printf("Enter the name to be searched for: ");
scanf("%s", sname); //sname is an array, no &
for (n = front, prev = NULL; n != NULL; prev = n, n = n->next) {
if (strcmp(sname, n->element->name) == 0) {
found = 1;
printf("phone = %d ", n->element->phone);
printf("email = %s ", n->element->email);
break;
}
}
if (!found) {
printf("The name does not exist. ");
}
else {
if (prev == NULL)
front = front->next;
else
prev->next = prev->next->next;
count--;
}
}
void printall() {
struct node *n;
int i;
for (n = front, i = 1; n != NULL; n = n->next, i++) {
printf("%2d) Name : %s ", i, n->element->name);
printf(" Phone: %d ", n->element->phone);
printf(" Email: %s ", n->element->email);
}
}
Contact Manager roblem Description: Enhance the Contact Manager reviewed in class. The program must be written in C, use structures, pointers and a Linked-List implementation. The following enhancements are to be added 1. Add a new element to the Contact structure which records the salary of the contact as a floating point. Make sure you update the insert, search and print functions to include this new field. When printing the salary, print it with a leading dollar sign and exactly two places after the decimal point. Define a function length, which recursively determines the length of the list. Define a function totalSalary, which recursively determines the total salary of the members of your list. When printing the list, print the Total number or contacts and average salary before the list of members (See an example of this in Required Outout, below a. For each member above the average by $1000 or more, place a +)before their salary. b. For each member below the average by $1000 or more, place a (-) before there salary c. For each member within $1000 of the average, place a (*) before their salary 2. 3. 4. Notes: . Start from contacts2.c (not contacts.c) Turn in only your completed contacts3.c file Look at the formatting options for printf to get your salary right. Absolute value function, abs(), is in
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
