Menu

(Solved) : Modify Requestc Laundrylistc Programs Adding Modifying Following Functions Add Delete Func Q37172433 . . .

Modify the request.c andlaundry_list.c programs by adding and modifyingthe following functions:

  1. Add a delete function in request.c that willdelete 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 the headerfile; modify the main function in laundry_list.cto add ‘d’ for delete option in the menu and itcalls the delete function when the ‘d’option isselected.

  2. Modify the append_to_list function so a request is insertedinto an ordered list (by last name and first name)and the list remains ordered after the insertion. For example, arequest by Ashley Meyers should be before a request by Justin Winnin the list; a request by Elizabeth Lewis should be after a book byAshely Lewis in the list. The order of the requests does not matterif multiple requests have the same names.

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

request.c

#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(“tInput room number: “);
scanf(“%d”, &roomNumber);

while (getchar() != ‘n’);
struct request *print = list;
if(list != NULL)
{
do
{
if(print->roomNumber == roomNumber)
{
printf(“tlaundry service request for this room existsalready.n”);
printf(“tUse 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 first name: “);
read_line(new_request->first, NAME_LEN);
printf(“tEnter last name: “);
read_line(new_request->last, NAME_LEN);
printf(“tEnter number of 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(“tInput room number: “);
scanf(“%d”, &roomNumber);

struct request *print = list;
while(print != NULL)
{
if(print->roomNumber == roomNumber)
{
int n;
printf(“tInput 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(“tRoomoom 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”);
}
}

request.h

#ifndef REQUEST_H_INCLUDED
#define REQUEST_H_INCLUDED
#define NAME_LEN 30

struct request
{
int roomNumber;
char first[NAME_LEN+1];
char last[NAME_LEN+1];
int num_items;
struct request *next;
};

struct request *append_to_list(struct request *list);
void update(struct request *list);
void printList(struct request *list);
void clearList(struct request *list);
int read_line(char str[], int n);

#endif

readline.c

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

#include “readline.h”

int read_line(char str[], int n)
{
int ch, i = 0;

while (isspace(ch = getchar()));

str[i++] = ch;
while ((ch = getchar()) != ‘n’) {
if (i < n)
str[i++] = ch;

}
str[i] = ”;
return i;
}

readline.h

#ifndef READLINE_H_INCLUDED
#define READLINE_H_INCLUDED

int read_line(char str[], int n);
// The READLINE_H_INCLUDED
#endif

makefile

readline.o: readline.c
   gcc -c readline.c

request.o: request.c
   gcc -c request.c

laundry_list.o: laundry_list.c
   gcc -c laundry_list.c

laundry_list: readline.o request.o laundry_list.o
   gcc -o laundry_list readline.o request.olaundry_list.o

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