Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify project 9 by adding and modifying the following functions: 1) Add a delete function in equipment.c that delete an equipment from the list. The

Modify project 9 by adding and modifying the following functions:

1) Add a delete function in equipment.c that delete an equipment from the list. The function should delete an equipment by its type and description. Type and description will be entered by the user. The function should have the following prototype:

 struct equipment* delete_from_list(struct equipment *list); 

You will also need to add the function prototype to the header file; modify the main function in group_equip.c to add d for delete option in the menu and it calls the delete function when the d option is selected.

2) Modify the append_to_list function so an equipment is inserted into an ordered list (by type, then by description) and the list remains ordered after the insertion. For example, dumbbell should be before stability ball in the list; stability ball, large should be beforestability ball, small in the list.

Here is my answer for part 1 but it isn't working. It keeps telling me equipment not found for the delete. I also added the function for part 2:

struct equipment *append_to_list(struct equipment *list){

struct equipment *temp = (struct equipment *)malloc(sizeof(struct equipment));

printf(" Enter equipment type : ");

read_line(temp->type, NAME_LEN);

printf(" Enter description: ");

read_line(temp->description, NAME_LEN);

printf(" Please enter quantity: ");

scanf("%d",&temp->quantity);

temp->next = NULL;

if(list == NULL){

list = temp;

}

else{

struct equipment *temp2 = list, *prev = NULL;

while (temp2 != NULL){

if (strcmp(temp2->type, temp->type) == 0 && strcmp(temp2->description, temp->description) == 0){

printf("Equipment already Exists ");

free(temp);

return list;

}

prev = temp2;

temp2 = temp2->next;

}

prev->next = temp;

}

return list;

}

struct equipment *delete_from_list(struct equipment *list){

if (list == NULL){

printf ("List is empty.");

return list;

}

int found = 0;

struct equipment *delete = (struct equipment *)malloc(sizeof(struct equipment));

struct equipment *cur = list, *temp = list->next, *temp2 = NULL;

printf (" Please enter the equipment type: ");

read_line(delete->type, NAME_LEN);

printf (" Please enter description: ");

read_line(delete->type, NAME_LEN);

if(strcmp(cur->type,delete->type) == 0 && strcmp(cur->description,delete->description) == 0){

found = 1;

list = list->next;

free(cur);

}

else{

while (temp != NULL){

if(strcmp(temp->type,delete->type) == 0 && strcmp(temp->description,delete->description) == 0){

found = 1;

temp2 = temp;

cur->next = temp->next;

free(temp2);

break;

}

cur = temp;

temp = temp->next;

}

}

if (!found)

printf ("Equipment not found. ");

return list;

}

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago