Menu

[Solved]Modify Requestc Laundrylistc Programs Adding Modifying Following Functions Add Delete Func Q37138236

  1. Modify the request.cand laundry_list.c programsby adding and modifying the followingfunctions:

    1. Add a delete function in request.c thatdelete a request. The function should delete a request from thelist by room number and person’s first and last name. Room numberand name will be entered by the user. The function should have thefollowing prototype:

      struct request* delete_from_list(struct request *list);

      You will also need to add the function prototype to theheader file; modify the main function in laundry_list.cto add ‘d’ for delete option in the menuand it calls the delete function when the ‘d’option is selected.

    2. Modify the append_to_list function so a request isinserted into an ordered list (by last name and first name) and thelist remains ordered after the insertion. For example, a requestby Ashley Meyers should be before a requestby Justin Winn in the list; a request byElizabeth Lewis should be after a book by AshelyLewis in the list. The order of the requests does notmatter if multiple requests have the same names.

/////////////////////////////////////////////////

/* request.c program */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include “request.h”
//#include “readline.h”

struct request *append_to_list(struct request *list)
{
int roomNumber;
printf(“tEnter the room number: “);
scanf(“%d”, &roomNumber);

while (getchar() != ‘n’);
struct request *print = list;
if(list != NULL)
{
do
{
if(print->roomNumber == roomNumber)
{
printf(“tA laundry service request for this room alreadyexists.n”);
printf(“tPlease use the update function to update the number ofitems.n”);
return list;
}
if(print->next != NULL)
{
print = print->next;
}
} while(print->next != NULL);
}

struct request *new_request = malloc(sizeof(structrequest));

new_request->roomNumber = roomNumber;
printf(“tEnter your first name: “);
read_line(new_request->first, NAME_LEN);
printf(“tEnter your last name: “);
read_line(new_request->last, NAME_LEN);
printf(“tEnter the number of laundry items: “);
scanf(“%d”, &new_request->num_items);

while (getchar() != ‘n’);
if(list == NULL)
{
list = new_request;
} else {
print->next = new_request;
}
return list;
}

void update(struct request *list)
{
int roomNumber;
printf(“tEnter your room number: “);
scanf(“%d”, &roomNumber);

struct request *print = list;
while(print != NULL)
{
if(print->roomNumber == roomNumber)
{
int n;
printf(“tEnter the number of items that will be added: “);
scanf(“%d”, &n);

while (getchar() != ‘n’);
print->num_items += n;
printf(“tService request has been updatedn”);
return;
}
print = print->next;
};

printf(“tThis room cannot be foundn”);
}

void printList(struct request *list)
{
struct request *print = list;
while(print != NULL)
{
printf(“tRoom Number: %dn”, print->roomNumber);
printf(“tName: %s %sn”, print->first, print->last);
printf(“tNumber of Items: %dn”, print->num_items);
printf(“n”);
print = print->next;
};
}

void clearList(struct request *list)
{
if(list == NULL)
{
return;
}

clearList(list->next);
free(list);
}

/////////////////////////////////////////////////

/* laundry_list.c */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include “request.h”
#include “readline.h”

int main(void)
{
char code;

struct request *new_list = NULL;
printf(“Operation Code: a for appending to the list, u for updatinga request”
“, p for printing the list; q for quit.nn”);
for (;;) {
printf(“Enter operation code: “);
scanf(” %c”, &code);
while (getchar() != ‘n’) /* skips to end of line */
;
switch (code) {
case ‘a’: new_list = append_to_list(new_list);
break;
case ‘u’: update(new_list);
break;
case ‘p’: printList(new_list);
break;
case ‘q’: clearList(new_list);
return 0;
default: printf(“tIllegal coden”);
}
printf(“n”);
}
}

Expert Answer


Answer to Modify the request.c and laundry_list.c programs by adding and modifying the following functions: Add a delete function… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *