Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Add a delete function in equipment.c that deletes an equipment from the list. The function should delete an equipment by its type and description.

1) Add a delete function in equipment.c that deletes 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);

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 before stability ball, small in the list.

Here's what I have so far. This is somehow not letting me append anything to the program.. please help!

#include #include #include #include #include "equipment.h" #define NAME_LEN 30 struct equipment *append_to_list(struct equipment *list) { struct equipment *q = (struct equipment *) malloc (sizeof(struct equipment)); printf("Enter type: "); scanf("%s", q -> type); printf("Enter description: "); scanf("%s", q -> description); printf("Enter quantity: "); scanf("%d", &q -> quantity); q -> next = NULL; if(list == NULL) list = q; else { struct equipment *p = list; while (p -> next != NULL) p = p -> next; p -> next = q; } return NULL; } void update(struct equipment *list) { char type[NAME_LEN + 1]; char description[NAME_LEN + 1]; int quantity; printf("Enter type :"); scanf("%s", type); printf("Enter description :"); scanf("%s", description); printf("Enter quantity :"); scanf("%d", &quantity); if (list == NULL) { printf("The list is empty "); } else { struct equipment *p = list; int found = 0; while(p!=NULL) { if (strcmp(p -> type, type) == 0 && strcmp(p -> description, description) == 0) { p -> quantity = quantity; found = 1; break; } p = p->next; } if (found == 0) printf("List not found "); else printf("List updated "); } } void printList(struct equipment *list) { if (list != NULL) { struct equipment *p = list; //while(p!=NULL) { printf("Type: %s ", p -> type); printf("Description: %s ", p -> description); printf("Quantity: %d ", p -> quantity); printf(" "); p = p -> next; } } else printf("The list is empty "); } void clearList(struct equipment *list) { if (list == NULL) { printf("The list is empty "); } else { struct equipment *p = list; while (list != NULL) { p = list; list = list->next; free(p); } } }

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 Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

analyze risk with capital project

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago