Question: #include #include readline.h #include equipment.h int main(void) { char code; struct equipment *e_list = NULL; printf(Operation Code: a for appending to the list, u for

#include
#include "readline.h" #include "equipment.h"
int main(void)
{
char code;
struct equipment *e_list = NULL;
printf("Operation Code: a for appending to the list, u for updating an equipment, p for printing the list; q for quit. ");
for (;;)
{
printf("Enter operation code: ");
scanf(" %c", &code);
while (getchar() != ' ') /* skips to end of line */
;
switch (code)
{
case 'a':
e_list = append_to_list(e_list);
break;
case 'u':
update(e_list);
break;
case 'p':
printList(e_list);
break;
case 'q':
clearList(e_list);
return 0;
default:
printf("Illegal code ");
}
printf(" ");
}
}
#include
#include
#include "equipment.h"
#include
#include "readline.h"
#define NAME_LEN 30
/*****************************************************
* append_to_list: allows user to input equipment type
* description and quantity. Then searches list and if
* already found does not append to list.
* **************************************************/
struct equipment *append_to_list(struct equipment *list)
{
struct equipment *new_node = (struct equipment *)malloc(sizeof(struct equipment));
printf("Enter equipment type: ");
read_line(new_node->type, NAME_LEN);
printf("Enter equipment Description: ");
read_line(new_node->description, NAME_LEN);
printf("Enter Equipment quantity: ");
scanf("%d", &new_node->quantity);
new_node->next = NULL;
if (list == NULL)
{
list = new_node;
}
else
{
struct equipment *temp = list, *prev;
while (temp != NULL)
{
if (strcmp(temp->type, new_node->type) == 0)
{
if (strcmp(temp->description, new_node->description) == 0)
{
printf("Equipment Already Exists ");
free(new_node);
return list;
}
if (strcmp(temp->description, new_node-> description) > 0)
{
if(strcmp(temp-> description, new_node ->description)) >0)
prev = temp;
temp = temp->next;
}
prev->next = new_node;
}
return list;
}
/***********************************************
* update: Allows user to update an item quantity
* that is already on the list
**********************************************/
void update(struct equipment *list)
{
char type[NAME_LEN + 1], descrip[NAME_LEN + 1];
int quantity;
printf("Enter Equipment type: ");
read_line(type, NAME_LEN);
printf("Enter Equipment Description: ");
read_line(descrip, NAME_LEN);
struct equipment *temp = list;
while (temp != NULL)
{
if (strcmp(temp->type, type) == 0 && strcmp(temp->description, descrip) == 0)
{
printf("Enter New equipment quantity: ");
scanf("%d", &quantity);
temp->quantity += quantity;
break;
}
temp = temp->next;
}
if (temp == NULL)
printf("Equipment Does not exist. ");
}
/*************************************************
* printlist: allows user to print all current
* items that have been added to list
************************************************/
void printList(struct equipment *list)
{
struct equipment *p = list;
printf(" TYPE DESCRIPTION QUANTITY ");
while (p != NULL)
{
printf("%-20s %-10s %-6d ", p->type, p->description, p->quantity);
p = p->next;
}
}
/*************************************************
* clearlist: Allows user to clear items in the
* list.
************************************************/
void clearList(struct equipment *list)
{
struct equipment *p = list, *prev = NULL;
while (p != NULL)
{
prev = p;
p = p->next;
free(prev);
}
}
struct equipment *delete_from_list(struct equipment *list)
{
char type[NAME_LEN + 1], descrip[NAME_LEN + 1];
printf("Enter Equipment type to be deleted: ");
read_line(type, NAME_LEN);
printf("Enter Equipment Description to be deleted: ");
read_line(descrip, NAME_LEN);
struct equipment *curr = list, *prev = NULL;
while (curr != NULL)
{
if (strcmp(curr->type, type) == 0 && strcmp(curr->description, descrip) == 0)
break;
prev = curr;
curr = curr->next;
}
if (curr == NULL)
printf("Equipment does not exist. ");
if (curr != NULL)
{
if(curr == list)
list=list->next;
else
prev->next = curr->next;
free(curr);
}
return list;
}
Project 11, Program Design 1. (70 points) Modify project 10 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, dumbbei should be before stability ball in the list; stability ball, large should be before stability ball, small in the list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
