[Solved] Part 1 Files Requestc Include Include Include Include Include Requesth Struct Request Appe Q37237018

Part 1 files:
request.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include “request.h”
struct request *append_to_list(struct request *list){
int room_number;
printf(“Enter room number: “);
scanf(“%d”, &room_number);
while (getchar() != ‘n’);
struct request *ptr = list;
if(list != NULL) {
do {
if(ptr->room_number == room_number) {
printf(“A request for this room already exists.n”);
printf(“Please use update function to update therequest.n”);
return list;
}
if(ptr->next != NULL) {
ptr = ptr->next;
}
} while(ptr->next != NULL);
}
struct request *newReq = malloc(sizeof(struct request));
newReq->room_number = room_number;
printf(“Enter first name: “);
read_line(newReq->first, NAME_LEN);
printf(“Enter last name: “);
read_line(newReq->last, NAME_LEN);
printf(“Enter number of items: “);
scanf(“%d”, &newReq->num_items);
while (getchar() != ‘n’);
if(list == NULL) {
list = newReq;
} else {
ptr->next = newReq;
}
return list;
}
void update(struct request *list)
{
int room_number;
printf(“Enter room number: “);
scanf(“%d”, &room_number);
struct request *ptr = list;
while(ptr != NULL) {
if(ptr->room_number == room_number) {
int n;
printf(“Enter number of items to be added: “);
scanf(“%d”, &n);
while (getchar() != ‘n’);
ptr->num_items += n;
printf(“updaetedn”);
return;
}
ptr = ptr->next;
};
printf(“No room exists with this room numbern”);
}
void printList(struct request *list){
struct request *ptr = list;
while(ptr != NULL) {
printf(“Room: %dn”, ptr->room_number);
printf(“%s %sn”, ptr->first, ptr->last);
printf(“numItems: %dn”, ptr->num_items);
printf(“n”);
ptr = ptr->next;
};
}
void clearList(struct request *list)
{
if(list == NULL) {
return;
}
clearList(list->next);
free(list);
}
request.h
#ifndef REQUEST_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define NAME_LEN 30
struct request{
int room_number;
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int read_line(char str[], int n);
#endif
lundry_list.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include “readline.h”
#include “request.h”
#define NAME_LEN 30
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.n”);
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(“Illegal coden”);
}
printf(“n”);
}
}
Makefile
laundry_list: laundry_list.o request.o readline.o
gcc -o laundry_list laundry_list.o request.oreadline.o
laundry_list.o: laundry_list.c
gcc -c laundry_list.c
request.o: request.c request.h
gcc -c request.c
readline.o: readline.c readline.h
gcc -c readline.c
Project 10, Program Design 1. (70 points) Modify project 9 by adding and modifying the following functions: 1) Add a delete function in request.c that delete a book. The function should delete a request from the list by room number and person’s first and last name. Room number and name will be entered by the user. The function should have the following prototype struct request* delete from_list (struct request list) You will also need to add the function prototype to the header file; modify the main function in laundry_list.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 a request is inserted into an ordered ist (by last name and first name) and the list remains ordered after the insertion. For example, a request by Ashley Meyers should be before a request by Justin Winn in the list; a request by Elizabeth Lewis should be after a book by Ashely Lewis in the list. The order of the requests does not matter if multiple requests have the same names. Show transcribed image text Project 10, Program Design 1. (70 points) Modify project 9 by adding and modifying the following functions: 1) Add a delete function in request.c that delete a book. The function should delete a request from the list by room number and person’s first and last name. Room number and name will be entered by the user. The function should have the following prototype struct request* delete from_list (struct request list) You will also need to add the function prototype to the header file; modify the main function in laundry_list.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 a request is inserted into an ordered ist (by last name and first name) and the list remains ordered after the insertion. For example, a request by Ashley Meyers should be before a request by Justin Winn in the list; a request by Elizabeth Lewis should be after a book by Ashely Lewis in the list. The order of the requests does not matter if multiple requests have the same names.
Expert Answer
Answer to Part 1 files: request.c #include #include #include #include #include “request.h” struct request *append_to_list(struct r… . . .
OR

