Question
I have this assignment due, but I have errors like (note: declared here c:169:7, and issues with return statements) was wondering if it could be
I have this assignment due, but I have errors like (note: declared here c:169:7, and issues with return statements) was wondering if it could be looked over to find the issues.
This is the assignment:
This is my adjusted code:
#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(); int length (struct node *); float TotalSalary(struct node *);
int 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); }
return 0; }
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); scanf("%f", &c->salary);
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("salary = %f ", n->element->salary); return; } }
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); printf("salary = %f ",n->element->salary); 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; int l = length(front); float total = TotalSalary(front); float average = total/l; printf("Members: total is %d, ",l); printf("Average salary is $%0.2f ", average);
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); printf(" Salary: "); if(n->element->salary -average>=1000)printf(" [+]$"); else if(average - n->element->salary>=1000)printf(" [-]$"); else if(abs(average- n->element->salary)element->salary); } }
int length (struct node *n){ if(n==NULL)return 0; return 1+length(n->next); }
float TotalSalary(struct node *n) { if(n==NULL)return 0.0; return (n->element->salary)+TotalSalary(n->next); return; }
Contact Manager Problem 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, delete, 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. 2. Define a function length, which recursively determines the length of the list. 3. Define a function totalSalary, which recursively determines the total salary of the members of your list. 4. 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 Output, below). 2. 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. 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
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