[Solved] C Programming Please Give Comments Onto Code Added Codes Readlinec Include Include Include Q37176853
(C Programming only) Pleasegive comments onto where each code should be added.
The codes:
Readline.c
#include <stdio.h>
#include <stdlib.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 <ctype.h>
int read_line(char str[], int n);
#endif
Request.c
#include <stdio.h>
#include <stdlib.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(structrequest));
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(“Updatedn”);
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
laundry_list.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include “request.h”
#include “readline.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 forupdating a request”
“, p for printing the list; q for quit.n”);
for (;;) {
printf(“Enter operation code: “);
scanf(” %c”, &code);
while (getchar() != ‘n’)
;
switch (code) {
case ‘a’: new_list = append_to_list(new_list);
break;
case ‘d’: new_list = delete_from_list(new_list); //added function
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”);
}
}
(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.cto 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 list (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 (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.cto 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 list (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 (C Programming only) Please give comments onto where each code should be added. The codes: Readline.c #include #include … . . .
OR

