Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the following code in the add your code part #include #include #include #include #define NAME_LEN 30 struct equipment{ char type[NAME_LEN+1]; char description[NAME_LEN+1]; int quantity;

image text in transcribed

Modify the following code in the "add your code" part

#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

str[i++] = ch;

}

str[i] = '\0';

return i;

}

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.ccontains 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: append_to_list: ask the user to enter an equipment's type, description, and quantity (in the exact order), then add the equipment to the end of the linked list. 1. It should check whether the equipment has already existed by type and description. If so, the function should print a message and exit. If the equipment does not exist, allocate memory for it, store the data, and append it to the end of the linked list. 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. a. b. C. update: update an equipment's quantity. Ask the user to enter the equipment's type and description, and quantity to be incremented. Find the matching equipment and update the quantity. If not found, print a message. printList: print the type, description, and quantity of all equipment in the list. clearList: when the user exists the program, all the memory allocated for the linked list should be deallocated. 2. 3. 4. Note: use read line function included in the program for reading in type and description

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions