Question: this is the code for project 8 #include #include #include #include #define TITLE_LEN 100 #define NAME_LEN 30 struct book{ char title[TITLE_LEN+1]; char first[NAME_LEN+1]; char last[NAME_LEN+1];

 this is the code for project 8 #include #include #include #include

this is the code for project 8

#include #include #include #include #define TITLE_LEN 100 #define NAME_LEN 30

struct book{

char title[TITLE_LEN+1]; char first[NAME_LEN+1]; char last[NAME_LEN+1]; double price; int num_requests; struct book *next; };

struct book *append_to_list(struct book *list);

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

int main(void) {

char code; struct book *book_list = NULL; printf("Operation Code: a for appending to the list, u for updating a book, p for printing the list, q for quit. "); for (;;) { printf("Enter operation code: "); scanf(" %c", &code); while (getchar() != ' ') ; switch (code) { case 'a': book_list = append_to_list(book_list); break; case 'u': update(book_list); break; case 'p': printList(book_list); break; case 'q': clearList(book_list); return 0; default: printf("Illegal code ");

}

printf(" "); } }

int present(struct book *list,char*title,char*first,char*last){ struct book*lis = list; if(list!=NULL){ if(strcmp(lis->title, title) == 0 && strcmp(lis->first, first) == 0 && strcmp(lis->last, last) == 0){ printf("You can update number of requests "); return(1); } lis=lis->next; } return(0); } struct book *append(struct book*list,struct book*new_node){ struct book*lis=list; if(list==NULL){ list = new_node; }

else{ while(lis->next!=NULL){

lis=lis->next; } lis->next=new_node; } return(list); }

struct book *append_to_list(struct book *list){ char cover[TITLE_LEN+1]; char firstN[NAME_LEN+1]; char lastN[NAME_LEN+1]; //We just ask user to input info. printf("Enter a book's title, author's first name, author's last name "); read_line(cover,100); read_line(firstN,30); read_line(lastN,30);

if(!present(list,cover,firstN,lastN)) { double prices = 0; int reqs = 0; printf("Please enter the price, and the request amount wanted: "); scanf("%lf%d",&prices,&reqs); struct book*new_node=(struct book*)malloc(sizeof(struct book)); strcpy(new_node->title,cover); strcpy(new_node->first,firstN); strcpy(new_node->last,lastN); new_node->price= prices; new_node->num_requests=reqs; new_node->next=NULL; list=append(list,new_node); } return list;

}

void update(struct book *list){

char cover[TITLE_LEN+1]; char firstN[NAME_LEN+1]; char lastN[NAME_LEN+1];

printf("Enter the title of the book, also the first name, and lastly the last name. ");

read_line(cover,100); read_line(firstN,30); read_line(lastN,30);

struct book*lis=list;

if(list!=NULL){ while(lis!=NULL){ if(strcmp(lis->title, cover) == 0 && strcmp(lis->first, firstN) == 0 && strcmp(lis->last, lastN) == 0){ printf("Please enter the amount of requests: "); scanf("%d",&lis->num_requests); return; } lis=lis->next; } } printf("Not in the list"); }

void printList(struct book *list){

struct book*lis=list;

while(lis!=NULL){

printf("Title: %s ",lis->title); printf("Prices: %lf ",lis->price); printf("Requests: %d ",lis->num_requests); lis=lis->next; printf(" "); } }

void clearList(struct book *list){ struct book* tmp; while (list != NULL){ tmp = list; list = list->next; } } //Given to us. 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] = '\0'; return i;

}

Would appreciate any help i can get.

1. (60 points) Modify Project 8 program so that the peogram is split into three source files and two header files 1) Put al functions related to operations on the list of books into book.e 2) Create a header file named book.hthat contains struet book declaration and prototypes for the functions in book.c. The header file should enclose the contents of the header file in an Endes-tendif pair to protect the file. 3) Put the read line function is in a separate file named readline.c 4) Create a header file named readline.h that contains a prototype for the read line function. The header file should enclose the contents of the header file in an inde-tendipair to protect the file. 5) book requests.c contains the main function 2. (40 points) Write a makefile to build the program on student cluster. The makefile should contain the following rules: 1 Build readline.o by compiling readline. 2) Build book.o by compiling book.c 3) Build book_requests.o by compiling book requests.e Build book requests by linking readline.o,book.o, and book requestso Each rule should include the name of the target file, dependencies among files, and the command to be executed. The makefile should name the executable file for the program book requests

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!