Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify project 9 by adding and modifying the following functions: 1) Add a delet

ID: 3713392 • Letter: M

Question

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:

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;

}

Explanation / Answer

The function isn't working because everytime your read_line you are storing that in delete->type and not delete description.

If you will change these statements like this then it will work

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->description, 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;

}

Do give a thumbs up and in case there are doubts leave a comment.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote