Question
A gym would like to maintain a list of the exercise equipment for its group fitness classes. Each exercise equipment was stored with the type,
A gym would like to maintain a list of the exercise equipment for its group fitness classes. Each exercise equipment was stored with the type, description (such as size or weight), and quantity. The program group_equip.c contains the equipment struct declaration, function prototypes, and the main function. Complete the function definitions so it uses a dynamically allocated linked list to store the equipment. Complete the following functions: 1. append_to_list: ask the user to enter an equipments type, description, and quantity (in the exact order), then add the equipment to the end of the linked list. a. It should check whether the equipment has already existed by type and description. If so, the function should print a message and exit. b. If the equipment does not exist, allocate memory for it, store the data, and append it to the end of the linked list. c. If the list is empty, the function should return the pointer to the newly created equipment. Otherwise, add the equipment to the end of the linked list and return the pointer to the linked list. 2. update: update an equipments quantity. Ask the user to enter the equipments type and description, and quantity to be incremented. Find the matching equipment and update the quantity. If not found, print a message. 3. printList: print the type, description, and quantity of all equipment in the list. 4. clearList: when the user exists the program, all the memory allocated for the linked list should be deallocated. Note: use read_line function included in the program for reading in type and description.
Group_equip.c
#include
#include
#include
#include
#define NAME_LEN 30
struct equipment{
char type[NAME_LEN+1];
char description[NAME_LEN+1];
int quantity;
struct equipment *next;
};
struct equipment *append_to_list(struct equipment *list);
void update(struct equipment *list);
void printList(struct equipment *list);
void clearList(struct equipment *list);
int read_line(char str[], int n);
/**********************************************************
* main: Prompts the user to enter an operation code, *
* then calls a function to perform the requested *
* action. Repeats until the user enters the *
* command 'q'. Prints an error message if the user *
* enters an illegal code. *
**********************************************************/
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(" ");
}
}
struct equipment *append_to_list(struct equipment *list){
//add your code
return NULL;
}
void update(struct equipment *list)
{
//add your code
}
void printList(struct equipment *list){
struct equipment *p;
//add your code
}
void clearList(struct equipment *list)
{
//add your code
}
int read_line(char str[], int n)
{
int ch, i = 0;
while (isspace(ch = getchar()))
;
str[i++] = ch;
while ((ch = getchar()) != ' ') {
if (i < n)
str[i++] = ch;
}
str[i] = '\0';
return i;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started