Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct node
- {
- char bookid[50];
- char bookname[100];
- char author[50];
- char category[50];
- char name[50];
- int quantity;
- struct node *next;
- } node;
- node *head_book=NULL,*ihead=NULL;
- node *search_id(node *list , char s[])
- {
- while(list!=NULL)
- {
- if(strcmp(list->bookid,s)==0)
- {
- return list;
- break;
- }
- list=list->next;
- }
- if(list==NULL)
- {
- return NULL;
- }
- }
- node *search_nm(char s[])
- {
- node *list=head_book;
- while(list!=NULL)
- {
- if(strcmp(list->bookname,s)==0)
- {
- return list;
- break;
- }
- list=list->next;
- }
- if(list==NULL)
- {
- return NULL;
- }
- }
- void search()
- {
- printf("1.Search by Id\n");
- printf("2.Search By Name\n");
- int x;
- printf("Select one:");
- scanf("%d",&x);
- if(x==1)
- {
- char temp[50];
- printf("Enter Book ID:");
- scanf(" %[^\n]",temp);
- node *n=search_id(head_book,temp);
- if(n==NULL)
- {
- printf("No Book Available\n");
- }
- else
- {
- printf("\nBook Is Available!!!!\n\n");
- printf("Book ID: %s\n",n->bookid);
- printf("Book Name: %s\n",n->bookname);
- printf("Author: %s\n",n->author);
- printf("Quantity: %d\n",n->quantity);
- }
- printf("\n1.back\n");
- printf("2.menu\n");
- printf("Choose One:");
- int y;
- scanf("%d",&y);
- if(y==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- else if(x==2)
- { char temp[50];
- printf("Enter Book Name:");
- scanf(" %[^\n]",temp);
- node *n=search_nm(temp);
- if(n==NULL)
- {
- printf("\nNo Book Available!!\n\n");
- }
- else
- {
- printf("\nBook Is Available\n\n");
- printf("Book ID: %s\n",n->bookid);
- printf("Book Name: %s\n",n->bookname);
- printf("Author: %s\n",n->author);
- printf("Quantity: %d\n\n",n->quantity);
- }
- printf("\n1.back\n");
- printf("2.menu\n");
- printf("Choose One:");
- int y;
- scanf("%d",&y);
- if(y==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- }
- void view()
- {
- node *list = head_book;
- int cm=0,e=0,c=0,m=0,a=0,tbook=0;
- while(list!=NULL)
- {
- if(strcmp(list->category,"Computer")==0)
- {
- printf("\nBook Id: %s\n",list->bookid);
- printf("book Name: %s\n",list->bookname);
- printf("Author: %s\n",list->author);
- printf("Category: %s\n",list->category);
- printf("Quantity: %d\n",list->quantity);
- cm++;
- }
- printf("\nTotal Computer Book:%d\n",cm);
- list=list->next;
- }
- list = head_book;
- while(list!=NULL)
- {
- if(strcmp(list->category,"Electronics")==0)
- {
- printf("\nBook Id: %s\n",list->bookid);
- printf("book Name: %s\n",list->bookname);
- printf("Author: %s\n",list->author);
- printf("Category: %s\n",list->category);
- printf("Quantity: %d\n",list->quantity);
- e++;
- }
- printf("\nTotal Electronics Book:%d\n",e);
- list=list->next;
- }
- list = head_book;
- while(list!=NULL)
- {
- if(strcmp(list->category,"Civil")==0)
- {
- printf("\nBook Id: %s\n",list->bookid);
- printf("book Name: %s\n",list->bookname);
- printf("Author: %s\n",list->author);
- printf("Category: %s\n",list->category);
- printf("Quantity: %d\n",list->quantity);
- c++;
- }
- list=list->next;
- }
- printf("\nTotal Civil Book:%d\n",c);
- list = head_book;
- while(list!=NULL)
- {
- if(strcmp(list->category,"Mechanical")==0)
- {
- printf("\nBook Id: %s\n",list->bookid);
- printf("book Name: %s\n",list->bookname);
- printf("Author: %s\n",list->author);
- printf("Category: %s\n",list->category);
- printf("Quantity: %d\n",list->quantity);
- m++;
- }
- list=list->next;
- }
- printf("\nTotal Mechanical Book:%d\n",m);
- list = head_book;
- while(list!=NULL)
- {
- if(strcmp(list->category,"Architecture")==0)
- {
- printf("\nBook Id: %s\n",list->bookid);
- printf("book Name: %s\n",list->bookname);
- printf("Author: %s\n",list->author);
- printf("Category: %s\n",list->category);
- printf("Quantity: %d\n",list->quantity);
- a++;
- }
- list=list->next;
- }
- printf("\nTotal Architecture Book:%d\n\n",a);
- printf("Total Book's = %d\n\n",a+cm+c+m+e);
- printf("\n1.menu\n");
- int x;
- printf("press 1\n");
- scanf("%d",&x);
- if(x==1)
- {
- menu();
- }
- else
- {
- menu();
- }
- }
- void addbook()
- {
- char temp[50];
- printf("\n1.Computer\n");
- printf("2.Electronics\n");
- printf("3.Civil\n");
- printf("4.Mechanical\n");
- printf("5.Architecture\n");
- printf("Select category:");
- int x;
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- strcpy(temp,"Computer");
- break;
- }
- case 2:
- {
- strcpy(temp,"Electronics");
- break;
- }
- case 3:
- {
- strcpy(temp,"Civil");
- break;
- }
- case 4:
- {
- strcpy(temp,"Mechanical");
- break;
- }
- case 5:
- {
- strcpy( temp,"Architecture");
- break;
- }
- default:
- {
- printf("Choose Correct option!!\n");
- addbook();
- break;
- }
- }
- char id[50];
- printf("\nEnter Book Id:");
- scanf(" %s",id);
- node *list=head_book;
- while(list!=NULL)
- {
- if(strcmp(list->bookid,id)==0)
- {
- printf("\nThis Book Id Already Exist!!\n\n");
- break;
- }
- list=list->next;
- }
- if(list==NULL)
- {
- node *n=(node*)malloc(sizeof(node));
- n->next=NULL;
- printf("Book Name:");
- scanf(" %[^\n]",n->bookname);
- printf("Author:");
- scanf(" %[^\n]",n->author);
- printf("Quantity:");
- scanf("%d",&n->quantity);
- strcpy(n->bookid,id);
- strcpy(n->category,temp);
- if(head_book==NULL)
- {
- head_book=n;
- }
- else
- {
- node *list=head_book;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=n;
- }
- }
- printf("\n1.Add More information\n");
- printf("2.Menu\n");
- printf("Choose one:");
- int y;
- scanf("%d",&y);
- if(y==1)
- {
- addbook();
- }
- else
- {
- menu();
- }
- }
- void Delete()
- { char ch[50];
- node *temp=NULL;
- printf("\nEnter Book Id:");
- scanf("%s",ch);
- node *list=head_book;
- if(head_book==NULL)
- {
- printf("\nThis Book Does not Exist!!\n\n");
- }
- else if(strcmp(head_book->bookid,ch)==0)
- {
- temp=head_book;
- head_book=head_book->next;
- free(temp);
- }
- else
- {
- while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
- {
- list=list->next;
- }
- if(list->next==NULL)
- {
- printf("\nThis Book Does not Exist!!\n\n");
- }
- else
- {
- temp=list->next;
- list->next=temp->next;
- free(temp);
- }
- }
- printf("1.delete Another\n");
- printf("2.Menu\n");
- int x;
- if(x==1)
- {
- Delete();
- }
- else
- {
- menu();
- }
- }
- ibook()
- { char ch[50];
- printf("Enter Book id:");
- scanf("%s",ch);
- node *n=search_id(head_book,ch);
- if(n==NULL)
- {
- printf("\nNo Record Found!!\n\n");
- }
- else
- {
- node *m=(node*)malloc(sizeof(node));
- m->next=NULL;
- printf("This Book Is available!");
- printf("There are %d unissued book in the library\n",n->quantity);
- printf("The book name is: %s\n",n->bookname);
- printf("Enter Student Name:");
- scanf(" %[^\n]",m->name);
- strcpy(m->bookid,n->bookid);
- strcpy(m->bookname,n->bookname);
- strcpy(m->category,n->category);
- printf("The Book of Id %s is Issued for 7 days\n",n->bookid);
- if(ihead==NULL)
- {
- ihead=m;
- }
- else
- {
- node *list=ihead;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=m;
- }
- }
- printf("\n1.issue another book\n");
- printf("2.menu\n");
- int y;
- printf("choose one:");
- scanf("%d",&y);
- if(y==1)
- {
- ibook();
- }
- else
- {
- menu();
- }
- }
- void vbook()
- {
- node *list=ihead;
- if(ihead==NULL)
- {
- printf("\nNo record found\n\n");
- }
- else
- {
- while(list!=NULL)
- {
- printf("Student Name: %s\n",list->name);
- printf("Book Name: %s\n",list->bookname);
- printf("Book Id: %s\n",list->bookid);
- printf("Category: %s\n\n",list->category);
- list=list->next;
- }
- }
- printf("\n1.back\n");
- printf("2.menu\n");
- int y;
- printf("Choose One:");
- scanf("%d",&y);
- if(y==1)
- {
- issu();
- }
- else
- {
- menu();
- }
- }
- void sissu()
- {
- printf("Enter Book id:");
- char ch[50];
- scanf("%s",ch);
- node *list=ihead;
- int count=0;
- if(ihead==NULL)
- {
- printf("\nNo record found!!\n");
- }
- else
- {
- while(list!=NULL)
- {
- if(strcmp(list->bookid,ch)==0)
- {
- printf("This book has taken by %s\n",list->name);
- count=1;
- }
- }
- printf("\n");
- if(count==0)
- {
- printf("\nNo record found!\n\n");
- }
- }
- printf("\n1.Another search\n");
- printf("2.Menu\n");
- int y;
- printf("choose one:");
- scanf("%d",&y);
- if(y==1)
- {
- sissu();
- }
- else
- {
- menu();
- }
- }
- void rissu()
- {
- printf("Enter book Id:");
- char ch[50];
- scanf("%s",ch);
- node *temp=NULL;
- if(ihead==NULL)
- {
- printf("no record found\n");
- }
- else if(strcmp(ihead->bookid,ch)==0)
- {
- temp=ihead;
- ihead=ihead->next;
- free(temp);
- }
- else
- {
- node *list=ihead;
- while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
- {
- list=list->next;
- }
- if(list->next==NULL)
- {
- printf("No record Found!!\n");
- }
- else
- {
- temp=list->next;
- list->next=temp->next;
- free(temp);
- }
- }
- printf("\n1.Remove another Issue\n");
- printf("2.Menu\n");
- int y;
- printf("Choose One:");
- scanf("%d",&y);
- if(y==1)
- {
- rissu();
- }
- else
- {
- menu();
- }
- }
- void issu()
- { printf("\n1.issue a book\n");
- printf("2.View Issue Book\n");
- printf("3.search Issue Book\n");
- printf("4.remove Issue Book\n ");
- printf("Choose one:");
- int x;
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- ibook();
- break;
- }
- case 2:
- {
- vbook();
- break;
- }
- case 3:
- {
- sissu();
- break;
- }
- case 4:
- {
- rissu();
- }
- default:
- {
- printf("\nYou Choose Wrong otion!!!\n");
- menu();
- break;
- }
- }
- }
- void edit()
- {
- char temp[50];
- printf("Enter Book id:");
- scanf("%s",temp);
- node *n=search_id(head_book,temp);
- if(n==NULL)
- {
- printf("\nNo record Found!!\n");
- }
- else
- {
- printf("\nNew book Name:");
- scanf(" %[^\n]",n->bookname);
- printf("Author Name:");
- scanf(" %[^\n]",n->author);
- printf("Quantity:");
- scanf("%d",&n->quantity);
- }
- printf("\n1.Edit Another Book\n");
- printf("2.menu\n");
- printf("Choose One:");
- int x;
- scanf("%d",&x);
- if(x==1)
- {
- edit();
- }
- else
- {
- menu();
- }
- }
- void menu()
- {
- printf("\n1.Add Book's\n");
- printf("2.Search Book's\n");
- printf("3.Delete Book's\n");
- printf("4.Issue Book's\n");
- printf("5.view book list\n");
- printf("6.Edit Book's\n");
- printf("7.Exit\n");
- int x;
- printf("Choose any One:");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- addbook();
- break;
- }
- case 2:
- {
- search();
- break;
- }
- case 3:
- {
- Delete();
- break;
- }
- case 4:
- {
- issu();
- break;
- }
- case 5:
- {
- view();
- break;
- }
- case 6:
- {
- edit();
- break;
- }
- case 7:
- {
- exit(0);
- break;
- }
- default :
- {
- printf("Choose Correct Option!!\n");
- menu();
- break;
- }
- }
- }
- int main()
- {
- printf(" LIBRARY MANAGEMENT\n");
- printf(" ____________________\n");
- menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement