Advertisement
afrinahoque

Project Final (Library Management System)

Dec 13th, 2019
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.86 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. typedef struct node
  6. {
  7.     char bookid[50];
  8.     char bookname[100];
  9.     char author[50];
  10.     char category[50];
  11.     char name[50];
  12.     int quantity;
  13.     struct node *next;
  14. } node;
  15.  
  16. node *head_book=NULL, *ihead=NULL;
  17.  
  18.  
  19. node *search_id(node *list , char s[])
  20. {
  21.  
  22.     while(list!=NULL)
  23.     {
  24.         if(strcmp(list->bookid,s)==0)
  25.         {
  26.             return list;
  27.             break;
  28.         }
  29.         list=list->next;
  30.     }
  31.     if(list==NULL)
  32.     {
  33.         return NULL;
  34.     }
  35. }
  36.  
  37.  
  38. node *search_nm(char s[])
  39. {
  40.     node *list=head_book;
  41.     while(list!=NULL)
  42.     {
  43.         if(strcmp(list->bookname,s)==0)
  44.         {
  45.             return list;
  46.             break;
  47.         }
  48.         list=list->next;
  49.     }
  50.     if(list==NULL)
  51.     {
  52.         return NULL;
  53.     }
  54. }
  55.  
  56. void search()
  57. {
  58.     printf("1.Search by Id\n");
  59.     printf("2.Search By Name\n");
  60.     int x;
  61.     printf("Select one:");
  62.     scanf("%d",&x);
  63.     if(x==1)
  64.     {
  65.         char temp[50];
  66.         printf("Enter Book ID:");
  67.         scanf(" %[^\n]",temp);
  68.         node *n=search_id(head_book,temp);
  69.         if(n==NULL)
  70.         {
  71.             printf("No Book Available\n");
  72.  
  73.         }
  74.         else
  75.         {
  76.             printf("\nBook Is Available!!!!\n\n");
  77.             printf("Book ID: %s\n",n->bookid);
  78.             printf("Book Name: %s\n",n->bookname);
  79.  
  80.             printf("Author: %s\n",n->author);
  81.             printf("Quantity: %d\n",n->quantity);
  82.  
  83.         }
  84.         printf("\n1.back\n");
  85.         printf("2.menu\n");
  86.         printf("Choose One:");
  87.         int y;
  88.         scanf("%d",&y);
  89.         if(y==1)
  90.         {
  91.             search();
  92.         }
  93.         else
  94.         {
  95.             menu();
  96.         }
  97.  
  98.  
  99.     }
  100.     else if(x==2)
  101.     {  char temp[50];
  102.         printf("Enter Book Name:");
  103.         scanf(" %[^\n]",temp);
  104.         node *n=search_nm(temp);
  105.         if(n==NULL)
  106.         {
  107.             printf("\nNo Book Available!!\n\n");
  108.  
  109.         }
  110.         else
  111.         {
  112.             printf("\nBook Is Available\n\n");
  113.             printf("Book ID: %s\n",n->bookid);
  114.             printf("Book Name: %s\n",n->bookname);
  115.  
  116.             printf("Author: %s\n",n->author);
  117.             printf("Quantity: %d\n\n",n->quantity);
  118.  
  119.         }
  120.         printf("\n1.back\n");
  121.         printf("2.menu\n");
  122.         printf("Choose One:");
  123.         int y;
  124.         scanf("%d",&y);
  125.         if(y==1)
  126.         {
  127.             search();
  128.         }
  129.         else
  130.         {
  131.             menu();
  132.         }
  133.  
  134.     }
  135. }
  136.  
  137.  
  138. void view()
  139. {
  140.     node *list = head_book;
  141.     int cm=0,e=0,c=0,m=0,a=0;
  142.     while(list!=NULL)
  143.     {
  144.         if(strcmp(list->category,"Computer")==0)
  145.     {
  146.         printf("\nBook Id: %s\n",list->bookid);
  147.         printf("book Name: %s\n",list->bookname);
  148.         printf("Author: %s\n",list->author);
  149.         printf("Category: %s\n",list->category);
  150.         printf("Quantity: %d\n",list->quantity);
  151.         cm++;
  152.     }
  153.  
  154.  
  155.         list=list->next;
  156.     }
  157.  
  158.      list = head_book;
  159.     while(list!=NULL)
  160.     {
  161.         if(strcmp(list->category,"Electronics")==0)
  162.     {
  163.         printf("\nBook Id: %s\n",list->bookid);
  164.         printf("book Name: %s\n",list->bookname);
  165.         printf("Author: %s\n",list->author);
  166.         printf("Category: %s\n",list->category);
  167.         printf("Quantity: %d\n",list->quantity);
  168.         e++;
  169.     }
  170.  
  171.         list=list->next;
  172.     }
  173.  
  174.  
  175.     list = head_book;
  176.     while(list!=NULL)
  177.     {
  178.         if(strcmp(list->category,"Civil")==0)
  179.     {
  180.         printf("\nBook Id: %s\n",list->bookid);
  181.         printf("book Name: %s\n",list->bookname);
  182.         printf("Author: %s\n",list->author);
  183.         printf("Category: %s\n",list->category);
  184.         printf("Quantity: %d\n",list->quantity);
  185.         c++;
  186.     }
  187.  
  188.         list=list->next;
  189.     }
  190.  
  191.  
  192.        list = head_book;
  193.     while(list!=NULL)
  194.     {
  195.         if(strcmp(list->category,"Mechanical")==0)
  196.     {
  197.         printf("\nBook Id: %s\n",list->bookid);
  198.         printf("book Name: %s\n",list->bookname);
  199.         printf("Author: %s\n",list->author);
  200.         printf("Category: %s\n",list->category);
  201.         printf("Quantity: %d\n",list->quantity);
  202.         m++;
  203.     }
  204.  
  205.         list=list->next;
  206.     }
  207.  
  208.  
  209.       list = head_book;
  210.     while(list!=NULL)
  211.     {
  212.         if(strcmp(list->category,"Architecture")==0)
  213.     {
  214.         printf("\nBook Id: %s\n",list->bookid);
  215.         printf("book Name: %s\n",list->bookname);
  216.         printf("Author: %s\n",list->author);
  217.         printf("Category: %s\n",list->category);
  218.         printf("Quantity: %d\n",list->quantity);
  219.         a++;
  220.     }
  221.  
  222.         list=list->next;
  223.     }
  224.     printf("\nTotal Computer Book:%d\n",cm);
  225.  
  226.  
  227.      printf("\nTotal Electronics Book:%d\n",e);
  228.  
  229.     printf("\nTotal Civil Book:%d\n",c);
  230.  
  231.        printf("\nTotal Mechanical Book:%d\n",m);
  232.  
  233.     printf("\nTotal Architecture Book:%d\n\n",a);
  234.  
  235.     printf("Total Book's = %d\n\n",a+cm+c+m+e);
  236.     printf("\n1.menu\n");
  237.     int x;
  238.     printf("press 1\n");
  239.     scanf("%d",&x);
  240.     menu();
  241.  
  242.  
  243. }
  244.  
  245. void addbook()
  246. {
  247.  
  248.   char temp[50];
  249.     printf("\n1.Computer\n");
  250.     printf("2.Electronics\n");
  251.     printf("3.Civil\n");
  252.     printf("4.Mechanical\n");
  253.     printf("5.Architecture\n");
  254.     printf("Select category:");
  255.     int x;
  256.     scanf("%d",&x);
  257.     switch(x)
  258.     {
  259.     case 1:
  260.     {
  261.         strcpy(temp,"Computer");
  262.         break;
  263.     }
  264.     case 2:
  265.     {
  266.         strcpy(temp,"Electronics");
  267.         break;
  268.     }
  269.     case 3:
  270.     {
  271.         strcpy(temp,"Civil");
  272.         break;
  273.     }
  274.     case 4:
  275.     {
  276.         strcpy(temp,"Mechanical");
  277.         break;
  278.     }
  279.     case 5:
  280.     {
  281.         strcpy( temp,"Architecture");
  282.         break;
  283.     }
  284.     default:
  285.     {
  286.         printf("Choose Correct option!!\n");
  287.         addbook();
  288.         break;
  289.     }
  290.     }
  291.     char id[50];
  292.     printf("\nEnter Book Id:");
  293.     scanf(" %s",id);
  294.  
  295.     node *list=head_book;
  296.         while(list!=NULL)
  297.         {
  298.             if(strcmp(list->bookid,id)==0)
  299.             {
  300.                 printf("\nThis Book Id Already Exist!!\n\n");
  301.                 break;
  302.             }
  303.             list=list->next;
  304.  
  305.         }
  306.         if(list==NULL)
  307.         {
  308.             node *n=(node*)malloc(sizeof(node));
  309.         n->next=NULL;
  310.              printf("Book Name:");
  311.     scanf(" %[^\n]",n->bookname);
  312.  
  313.     printf("Author:");
  314.     scanf(" %[^\n]",n->author);
  315.     printf("Quantity:");
  316.     scanf("%d",&n->quantity);
  317.     strcpy(n->bookid,id);
  318.     strcpy(n->category,temp);
  319.     if(head_book==NULL)
  320.     {
  321.         head_book=n;
  322.     }
  323.     else
  324.     {
  325.         node *list=head_book;
  326.         while(list->next!=NULL)
  327.         {
  328.             list=list->next;
  329.         }
  330.         list->next=n;
  331.     }
  332.  
  333.         }
  334.  
  335.  
  336.  
  337.  
  338.  
  339.     printf("\n1.Add More information\n");
  340.     printf("2.Menu\n");
  341.     printf("Choose one:");
  342.     int y;
  343.     scanf("%d",&y);
  344.     if(y==1)
  345.     {
  346.  
  347.             addbook();
  348.  
  349.  
  350.  
  351.     }
  352.     else
  353.     {
  354.         menu();
  355.     }
  356. }
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363. void Delete()
  364. {   char ch[50];
  365.     node *temp=NULL;
  366.     printf("\nEnter Book Id:");
  367.     scanf("%s",ch);
  368.     node *list=head_book;
  369.     if(head_book==NULL)
  370.     {
  371.         printf("\nThis Book Does not Exist!!\n\n");
  372.     }
  373.     else if(strcmp(head_book->bookid,ch)==0)
  374.     {
  375.         temp=head_book;
  376.         head_book=head_book->next;
  377.         free(temp);
  378.         printf("\n\nDeleted!!!\n\n");
  379.     }
  380.     else
  381.     {
  382.         while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
  383.         {
  384.             list=list->next;
  385.         }
  386.         if(list->next==NULL)
  387.         {
  388.             printf("\nThis Book Does not Exist!!\n\n");
  389.         }
  390.         else
  391.         {
  392.             temp=list->next;
  393.             list->next=temp->next;
  394.             free(temp);
  395.         }
  396.         printf("\n\nDeleted!!!\n\n");
  397.     }
  398.  
  399.     printf("1.delete Another\n");
  400.     printf("2.Menu\n");
  401.     int x;
  402.     if(x==1)
  403.     {
  404.         Delete();
  405.     }
  406.     else
  407.     {
  408.         menu();
  409.     }
  410.  
  411. }
  412. ibook()
  413. {   char ch[50];
  414.     printf("Enter Book id:");
  415.     scanf("%s",ch);
  416.     node *n=search_id(head_book,ch);
  417.     if(n==NULL)
  418.     {
  419.         printf("\nNo Record Found!!\n\n");
  420.     }
  421.     else
  422.     {
  423.     node *m=(node*)malloc(sizeof(node));
  424.     m->next=NULL;
  425.         printf("This Book Is available!");
  426.         printf("There are %d unissued book in the library\n",n->quantity);
  427.         printf("The book name is: %s\n",n->bookname);
  428.         printf("Enter Student Name:");
  429.         scanf(" %[^\n]",m->name);
  430.         strcpy(m->bookid,n->bookid);
  431.         strcpy(m->bookname,n->bookname);
  432.         strcpy(m->category,n->category);
  433.         printf("The Book of Id %s is Issued for 7 days\n",n->bookid);
  434.         if(ihead==NULL)
  435.         {
  436.             ihead=m;
  437.         }
  438.         else
  439.         {
  440.             node *list=ihead;
  441.             while(list->next!=NULL)
  442.             {
  443.                 list=list->next;
  444.             }
  445.             list->next=m;
  446.         }
  447.  
  448.     }
  449.  
  450.     printf("\n1.issue another book\n");
  451.     printf("2.menu\n");
  452.    int y;
  453.    printf("choose one:");
  454.    scanf("%d",&y);
  455.    if(y==1)
  456.    {
  457.        ibook();
  458.    }
  459.    else
  460.    {
  461.        menu();
  462.    }
  463. }
  464.  
  465. void vbook()
  466. {
  467.     node *list=ihead;
  468.     if(ihead==NULL)
  469.     {
  470.         printf("\nNo record found\n\n");
  471.     }
  472.     else
  473.     {
  474.         while(list!=NULL)
  475.         {
  476.             printf("Student Name: %s\n",list->name);
  477.             printf("Book Name: %s\n",list->bookname);
  478.             printf("Book Id: %s\n",list->bookid);
  479.             printf("Category: %s\n\n",list->category);
  480.             list=list->next;
  481.         }
  482.     }
  483.     printf("\n1.back\n");
  484.     printf("2.menu\n");
  485.     int y;
  486.     printf("Choose One:");
  487.     scanf("%d",&y);
  488.     if(y==1)
  489.     {
  490.         issu();
  491.     }
  492.     else
  493.     {
  494.         menu();
  495.     }
  496. }
  497.  
  498.  
  499. void sissu()
  500. {
  501.     printf("Enter Book id:");
  502.     char ch[50];
  503.     scanf("%s",ch);
  504.     node *list=ihead;
  505.     int count=0;
  506.     if(ihead==NULL)
  507.     {
  508.         printf("\nNo record found!!\n");
  509.     }
  510.     else
  511.     {
  512.         while(list!=NULL)
  513.         {
  514.             if(strcmp(list->bookid,ch)==0)
  515.             {
  516.                 printf("This book has taken by %s\n",list->name);
  517.                 count=1;
  518.             }
  519.         }
  520.         printf("\n");
  521.         if(count==0)
  522.         {
  523.             printf("\nNo record found!\n\n");
  524.         }
  525.     }
  526.     printf("\n1.Another search\n");
  527.     printf("2.Menu\n");
  528.     int y;
  529.     printf("choose one:");
  530.     scanf("%d",&y);
  531.     if(y==1)
  532.     {
  533.         sissu();
  534.     }
  535.     else
  536.     {
  537.         menu();
  538.     }
  539.  
  540. }
  541. void rissu()
  542. {
  543.     printf("Enter book Id:");
  544.     char ch[50];
  545.     scanf("%s",ch);
  546.     node *temp=NULL;
  547.     if(ihead==NULL)
  548.     {
  549.         printf("no record found\n");
  550.     }
  551.   else if(strcmp(ihead->bookid,ch)==0)
  552.     {
  553.         temp=ihead;
  554.         ihead=ihead->next;
  555.         free(temp);
  556.     }
  557.     else
  558.     {
  559.         node *list=ihead;
  560.         while(strcmp(list->next->bookid,ch)!=0&&list->next!=NULL)
  561.         {
  562.             list=list->next;
  563.         }
  564.         if(list->next==NULL)
  565.         {
  566.             printf("No record Found!!\n");
  567.         }
  568.         else
  569.         {
  570.             temp=list->next;
  571.             list->next=temp->next;
  572.             free(temp);
  573.         }
  574.     }
  575.     printf("\n1.Remove another Issue\n");
  576.     printf("2.Menu\n");
  577.     int y;
  578.     printf("Choose One:");
  579.     scanf("%d",&y);
  580.     if(y==1)
  581.     {
  582.         rissu();
  583.     }
  584.     else
  585.     {
  586.         menu();
  587.     }
  588. }
  589.  
  590. void issu()
  591. {   printf("\n1.issue a book\n");
  592.     printf("2.View Issue Book\n");
  593.     printf("3.search Issue Book\n");
  594.     printf("4.remove Issue Book\n ");
  595.     printf("Choose one:");
  596.     int x;
  597.     scanf("%d",&x);
  598.     switch(x)
  599.     {
  600.     case 1:
  601.         {
  602.             ibook();
  603.             break;
  604.  
  605.         }
  606.     case 2:
  607.         {
  608.             vbook();
  609.              break;
  610.         }
  611.     case 3:
  612.         {
  613.             sissu();
  614.             break;
  615.         }
  616.     case 4:
  617.         {
  618.             rissu();
  619.         }
  620.     default:
  621.         {
  622.             printf("\nYou Choose Wrong otion!!!\n");
  623.             menu();
  624.             break;
  625.         }
  626.     }
  627. }
  628. void edit()
  629. {
  630.     char temp[50];
  631.     printf("Enter Book id:");
  632.     scanf("%s",temp);
  633.     node *n=search_id(head_book,temp);
  634.     if(n==NULL)
  635.     {
  636.         printf("\nNo record Found!!\n");
  637.     }
  638.     else
  639.     {
  640.         printf("\nNew book Name:");
  641.         scanf(" %[^\n]",n->bookname);
  642.         printf("Author Name:");
  643.         scanf(" %[^\n]",n->author);
  644.         printf("Quantity:");
  645.         scanf("%d",&n->quantity);
  646.     }
  647.  
  648.     printf("\n1.Edit Another Book\n");
  649.     printf("2.menu\n");
  650.     printf("Choose One:");
  651.     int x;
  652.     scanf("%d",&x);
  653.     if(x==1)
  654.     {
  655.         edit();
  656.     }
  657.     else
  658.     {
  659.         menu();
  660.     }
  661. }
  662.  
  663. void menu()
  664. {
  665.     printf("\n1.Add Books\n");
  666.     printf("2.Search Books\n");
  667.     printf("3.Delete Books\n");
  668.     printf("4.Issue Books\n");
  669.     printf("5.view book list\n");
  670.     printf("6.Edit Books\n");
  671.     printf("7.Exit\n");
  672.     int x;
  673.     printf("Choose any One:");
  674.     scanf("%d",&x);
  675.     switch(x)
  676.     {
  677.     case 1:
  678.     {
  679.  
  680.             addbook();
  681.  
  682.  
  683.  
  684.         break;
  685.     }
  686.     case 2:
  687.     {
  688.         search();
  689.         break;
  690.     }
  691.     case 3:
  692.     {
  693.         Delete();
  694.         break;
  695.     }
  696.     case 4:
  697.     {
  698.         issu();
  699.         break;
  700.     }
  701.     case 5:
  702.     {
  703.         view();
  704.         break;
  705.     }
  706.     case 6:
  707.     {
  708.         edit();
  709.         break;
  710.     }
  711.     case 7:
  712.     {
  713.         exit(0);
  714.         break;
  715.     }
  716.  
  717.     default :
  718.     {
  719.         printf("Choose Correct Option!!\n");
  720.         menu();
  721.         break;
  722.     }
  723.     }
  724.  
  725. }
  726.  
  727. int main()
  728. {
  729.     printf("                                                                                                        LIBRARY MANAGEMENT\n");
  730.     printf("                                                                                                       ____________________\n");
  731.     menu();
  732. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement