Design the steps that one would follow to find a list of books in a library and
ID: 3626041 • Letter: D
Question
Design the steps that one would follow to find a list of books in a library and check out the books on the list from the library. Use procedure abstraction. Your design should contain a sequence of at least two high-level tasks. Your design should then refine these high-level tasks into more detailed tasks that contain sequence, selection and loop statements.Explanation / Answer
#include stdio.h #include conio.h #include io.h #include fcntl.h #include string.h #include stdlib.h #include alloc.h #include dos.h int display(); long int getsize(char[]); void editb(); void edits(); void bkst(); void stst(); void issue(); void viewret(); void retbook(); void bklt(); void stlt(); typedef struct date DATE; DATE dt,is,rt; int dtest; typedef struct { char sno[6]; char name[20]; float fine; char dept[3]; int token; }student; typedef struct { char bno[5]; char bname[50]; char aname[20]; DATE iss; DATE ret; char status[1]; char isto[6]; int cost; char descpt[200]; }book; int id,im,iy,rd,rm,ry; void assign(book *b) { b->iss.da_year=iy; b->iss.da_mon=im; b->iss.da_day=id; b->ret.da_day=rd; b->ret.da_mon=rm; b->ret.da_year=ry; return; } void main() { int opt; clrscr(); while(1) { if(dtest!=1) { getdate(&dt); is=dt; rt=dt; iy=is.da_year; im=is.da_mon; id=is.da_day; rt.da_day+=15; if(rt.da_day>31) { rt.da_day-=31; rt.da_mon+=1; } rd=rt.da_day; rm=rt.da_mon; ry=rt.da_year; dtest=1; } opt=display(); switch(opt) { case 1: editb(); continue; case 2: edits(); continue; case 3: stst(); continue; case 4: bkst(); continue; case 9: stlt(); continue; case 8: bklt(); continue; case 0: exit(0); break; case 5: issue(); continue; case 7: retbook(); continue; case 6: viewret(); continue; default: continue; } } } long int getsize(char a[]) { int file,size; file = open(a,O_RDONLY); size=filelength(file); close(file); if (sizebno); if((int)cmp==0) { flag=1; break; } } if(flag==1) { printf(" Book is aldready present! "); i--; continue; } printf("Name of the book:"); scanf("%s",(bk+i)->bname); printf("Author Name:"); scanf("%s",(bk+i)->aname); printf("Enter the cost of the book:"); scanf("%d",&(bk+i)->cost); (bk+i)->status[0]='N'; printf("Enter a short description :"); scanf("%s",(bk+i)->descpt); } fp=fopen("book.rrn","w+"); fwrite(bk,sizeof(book),(n+size),fp); printf("%d book(s) added succesfully!",n); fcloseall(); getch(); clrscr(); return; case 2: printf(" Enter the number of the book:"); scanf("%s",bn); if(size==0) { printf("Book list does not exist!"); getch(); clrscr(); return; } fp=fopen("book.rrn","r+"); fread(bk,sizeof(book),size,fp); fcloseall(); for(i=0;ibno,strlen(bn))==0) { flag=1; break; } } if(flag!=1) { printf(" The entered book id is invalid."); getch(); clrscr(); return; } if((bk+i)->status[0]=='Y') { printf(" Cannot delete the book.The book has been issued!"); getch(); return; } for(;isno); for(temp=0;tempsno,(st+temp)->sno,6); if((int)cmp==0) { flag=1; break; } } if(flag==1) { printf(" Student aldready present in the list! "); i--; continue; } printf("Name of the student:"); scanf("%s",(st+i)->name); printf("Department:"); scanf("%s",(st+i)->dept); (st+i)->token=0; (st+i)->fine=0; } fp=fopen("student.rrn","w+"); fwrite(st,sizeof(student),(n+size),fp); printf("%d student(s) added succesfully!",n); fcloseall(); getch(); clrscr(); return; case 2: printf(" Enter the number of the student:"); scanf("%s",bn); if(size==0) { printf("Student list does not exist!"); getch(); clrscr(); return; } fp=fopen("student.rrn","r+"); fread(st,sizeof(student),size,fp); fcloseall(); for(i=0;isno,strlen(bn))==0) { flag=1; break; } } if(flag!=1) { printf(" The entered student id is invalid."); getch(); clrscr(); return; } if((st+i)->token>0) { printf(" Cannot delete the student.The student has borrowed books from library!"); getch(); return; } for(;isno,bn,6); if((int)cmp==0) { flag=1; break; } } if(flag!=1) { printf(" The entered student id is invalid."); getch(); clrscr(); return; } clrscr(); printf(" STUDENT DETAILS"); printf(" Student name:%s",(st+i)->name); printf(" Department:%s",(st+i)->dept); printf(" Tokens Used: %d",(st+i)->token); printf(" Fine:%.2f",(st+i)->fine); if((st+i)->token==0) { getch(); clrscr(); return; } else if((st+i)->token!=0) { bsize1=getsize("book.rrn"); size1=(bsize1)/sizeof(book); fp=fopen("book.rrn","r"); bk=(book*)malloc((size1)*sizeof(book)); fread(bk,sizeof(book),size1,fp); fcloseall(); printf(" BOOK(S) BORROWED FROM THE LIBRARY: "); for(i=0;iisto,6); if((int)chk==0&&(bk+i)->status[0]=='Y') printf(" Book.No:%s Book Name:%s Issue:%d-%d-%d Expected Return:%d-%d-%d ", (bk+i)->bno,(bk+i)->bname,(bk+i)->iss.da_day, (bk+i)->iss.da_mon,(bk+i)->iss.da_year, (bk+i)->ret.da_day,(bk+i)->ret.da_mon,(bk+i)->ret.da_year); } printf(" Press any key........"); getch(); clrscr(); return; } } void bkst() { int size,i,flag=0,bsize; student *st; book *bk; FILE *fp; char bn[6]; bsize=getsize("book.rrn"); size=(bsize)/sizeof(book); bk=(book*)malloc((size)*sizeof(book)); printf(" Enter the number of the book:"); scanf("%s",bn); if(size==0) { printf("Book list does not exist!"); getch(); clrscr(); return; } fp=fopen("book.rrn","r+"); fread(bk,sizeof(book),size,fp); fcloseall(); for(i=0;ibno,bn,6); if((int)cmp==0) { flag=1; break; } } if(flag!=1) { printf(" The entered book id is invalid."); getch(); clrscr(); return; } clrscr(); printf(" BOOK DETAILS"); printf(" Book name:%s",(bk+i)->bname); printf(" Author Name:%s",(bk+i)->aname); printf(" Cost:Rs %d.00",(bk+i)->cost); printf(" Desciption:%s",(bk+i)->descpt); if((bk+i)->status[0]=='Y') { char temp[6]; strncpy(temp,(bk+i)->isto,6); printf(" Status:Issued"); printf(" Issued to: %.6s",temp); printf(" Date of issue:%d/%d/%d",(bk+i)->iss.da_day, (bk+i)->iss.da_mon,(bk+i)->iss.da_year); printf(" Expected date of return:%d/%d/%d", (bk+i)->ret.da_day,(bk+i)->ret.da_mon,(bk+i)->ret.da_year); } else printf(" Status:Not Issued"); getch(); clrscr(); return; } int display() { int op; char msg[26]; clrscr(); printf(" LIBMAN-A Library Management Software "); printf(" Date :%d/%d/%d ",dt.da_day,dt.da_mon,dt.da_year); printf(" 1.Edit book list"); printf(" 2.Edit Student list"); printf(" 3.Student status"); printf(" 4.Book status"); printf(" 5.Issue"); printf(" 6.View books"); printf(" 7.Return Books"); printf(" 8.View book list"); printf(" 9.View student list"); strcpy(msg,"0.Exit Enter your choice:"); printf(" %s",msg); scanf("%d",&op); return op; } void issue() { char bno[6],sno[6]; int size,bsize,i,flag=0,size1,bsize1,j,flag1=0,flag2=0,flag3=0; char msg[22]; FILE *fp; book *bk; student *st; flag1=flag2=flag=flag3=0; strcpy(msg,"Enter the book number:"); printf(" %s",msg); scanf("%s",bno); bsize=getsize("book.rrn"); size=bsize/sizeof(book); if(size==0) { printf(" Booklist does not exist!"); getch(); return; } fp=fopen("book.rrn","r+"); bk=(book*)malloc(size*sizeof(book)); fread(bk,sizeof(book),size,fp); fcloseall(); for(i=0;ibno,strlen(bno)); if((int)temp==0) { flag=1; break; } } if((bk+i)->status[0]=='N') flag3=1; if(flag==1 && flag3==1) { printf("Enter the student no:"); scanf("%s",sno); bsize1=getsize("student.rrn"); size1=bsize1/sizeof(student); fp=fopen("student.rrn","r+"); st=(student*)malloc(size1*sizeof(student)); fread(st,sizeof(student),size1,fp); fcloseall(); for(j=0;jsno,strlen(sno)); if(temp==0) { flag1=1; break; } } if(flag1==1&&flag==1) { if((st+j)->tokencost; strcpy((bk+i)->isto,sno); (bk+i)->status[0]='Y'; (bk+i)->cost=price; assign(bk+i); fwrite(bk,sizeof(book),size,fp); fcloseall(); fp=fopen("student.rrn","w+"); (st+j)->token+=1; fwrite(st,sizeof(student),size1,fp); fcloseall(); getch(); } } } if(flag!=1) printf(" Invalid Book Number!"); else if(flag3!=1) printf(" Book has aldready been issued!"); else if(flag1!=1) printf(" Invalid student number!"); else if(flag2!=1) printf(" Tokens Exhausted!"); else priRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.