Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribedimage text in transcribed

This is my adjusted code:

#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(); 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 The functions that are required to be recursive, must be recursive! Required Input: Commands (i, d, s, p, q) and required contact data. Required Output: Your output should look something like the following example. It must contain your name. Enhanced Contact Manager: Prof. Eckert Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries Q: guit Enter name, phone, email, salary: Bob 1234567 mail@emcc.edu 5000 The number of entries = 1 Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries q: quit Members: total is 1, average salary is $5000.00 1) Name : Bob Phone : 1234567 Email : maill@emcc.edu Salary: [*] $5000.00 Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries q: quit Enter name, phone, email, salary: Cindy 2345678 mail2emcc.edu 7000 The number of entries - 2 Enter your selection i: insert a new entry d: delete an entry s: search an entry p: print all entries q: quit Members: total is 2, average salary is $6000.00 1) Name : Cindy Phone : 2345678 Email : mail2 Cemcc.edu Salary: [+] $7000.00 2) Name : Bob Phone : 1234567 Email : mail@emcc.edu Salary: (-) 65000.00 Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries Q: quit Enter name, phone, email, salary: Greg 3456789 mail3emcc.edu 8500 The number of entries = 3 Enter your selection i: insert a new entry a: delete an entry 3: search an entry p: print all entries Q: quit Members: total is 3, average salary is $6933.33 1) Name : Greg Phone : 3456789 Email : mail@emcc.edu Salary: [+$8500.00 2) Name : Cindy Phone : 2345678 Email : mail2@emcc.edu Salary: [*] $7000.00 3) Name : Bob Phone : 1234567 Email : mail1@emcc.edu Salary: (-) 65000.00 Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries Q: quit d please enter the name to be searched for: Cindy phone = 2345678 email = mail2 @emcc.edu salary = $7000.00 Enter your selection i: insert a new entry d: delete an entry 3: search an entry P: print all entries q: quit Members: total is 2, average salary is $6750.00 1) Name : Greg Phone : 3456789 Email : mai13 Cemcc.edu Salary: [+] $9500.00 2) Name : Bob Phone : 1234567 Email : maill@emcc.edu Salary: [-$5000.00 Enter your selection i: insert a new entry d: delete an entry 3: search an entry p: print all entries Qquit g

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago