Advertisement
Sheyshya

Library management system 5

May 9th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 27.73 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5. #include<windows.h>
  6.  
  7.  
  8. // profile structure
  9. struct profile {
  10.     char name[100];
  11.     char firstname[40];
  12.     char lastname[40];
  13.     char address[40];
  14.     long long int phoneNumber;
  15.     int userID ;
  16.  
  17. };
  18. //books structure
  19. struct books
  20. {   int userid;
  21.     int issuemonth;
  22.     int day,month,year;
  23.     int issueday;
  24.     int issueyear;
  25.     int submitmonth;
  26.     int submitday;
  27.     int submityear;
  28.     long long int isbn;
  29.     char user[50];
  30.     char bookname[50];
  31.     int quantity;
  32. };
  33. int userid1;
  34. long long int isbn1;
  35.  
  36. //Profjile Functions List
  37. void mainMenu();
  38. void adduser();
  39. void deluser();
  40. void edituser();
  41. void listuser();
  42. void searchuser();
  43. void adminlogin();
  44.  
  45. //book functions list
  46. void booksection();
  47. void addbook();
  48. void listbook();
  49. void searchbook();
  50. void delbook();
  51. void editbook();
  52. void viewissuedbook();
  53. void issuemain();
  54. void borrowbook();
  55. void returnbook();
  56. void fine();
  57.  
  58.  
  59. //main function.
  60. int main()
  61. {
  62.     system("color f");  //sets system color to bright white.
  63.   adminlogin();
  64.    return 0;
  65. }
  66.  
  67. void adminlogin()   //sets up admin login window.
  68. {
  69.     int i=0;
  70.     char aa[20],ch;
  71.     char password[30];
  72.     char username[30];
  73.     start:
  74.    printf("\t\t\t..............................................\n");
  75.     printf("\t\t\t\t\t[ADMIN LOGIN]                \n\n");
  76.     printf("\t\t\tEnter your username: ");
  77.     scanf("%s",username);
  78.      printf("\t\t\tEnter your password: ");
  79.     while(ch!=13)
  80.    {
  81.  ch=_getch();
  82.  
  83.  if(ch!=13){
  84.  putch('*');
  85.  password[i] = ch;
  86.  i++;
  87.  }
  88.    }
  89.    password[i] = '\0';
  90.  
  91.  
  92.     if(strcmp(username,"a")==0){
  93.  
  94.    if(strcmp(password,"b")==0)
  95.    {
  96.        printf("\n\n");
  97.        char loading[]="\t\t\t\tloading.....................................!!\n";
  98.         while(loading[i]!='\0')
  99.     {
  100.         Sleep(50);
  101.         printf("%c",loading[i]);
  102.         i++;
  103.     }
  104.  
  105.  
  106.         printf("\n                                      Login Success!!\n\n");
  107.         printf("\n                                Enter any key to continue! \n\n");
  108.         _getch();
  109.         mainMenu();
  110.     }
  111.    else{
  112.         printf("\n\n");
  113.        printf("\t\t\t..............................................\n");
  114.  
  115.     printf("\n                                      Wrong Password!!\n\n");
  116.     remsk:
  117.         printf("\n");
  118.     printf("\t\t\tWould you like to try again?[yes?/no?]: ");
  119.     scanf("%s",aa);
  120.  
  121.     if (strcmp(aa,"yes")==0)
  122.      {
  123.         system("cls");   //clears the screen before proceeding to the next step.
  124.       adminlogin();
  125.  
  126. }
  127.         if (strcmp(aa,"no")==0)
  128.         {
  129.            exit(0);
  130.         }
  131.         else if(1)
  132.         {
  133.             system("cls");
  134.             printf("\n");
  135.             printf("\t\t\tInvalid choice. Enter [yes/no] only!");
  136.             goto remsk;
  137.         }
  138.  
  139. }
  140.     }else{
  141.         printf("\n\n");
  142.        printf("\t\t\t..............................................\n");
  143.     printf("\n                                     User doesn't exist!\n\n\n\n");
  144.    goto remsk;
  145. }
  146.  
  147. _getch();
  148. mainMenu();
  149. }
  150.  
  151. //For Main Menu
  152. void mainMenu(){
  153.     system("color E");//yellow
  154.     system("cls");
  155.     printf("\t\t\t...........................................\n");
  156.     printf("\t\t\t:\t\t[MAIN MENU]\t          :\n");
  157.     printf("\t\t\t:.........................................:\n");
  158.     printf("\n\n\n\t\t\t1.Register user\n\t\t\t2.List users\n\t\t\t3.Edit user\n\t\t\t4.Delete User\n\t\t\t5.Search user\n\t\t\t6.Book section\n\t\t\t7.Exit\n");
  159.     printf("\t\t\tPress (1-7)\n");
  160.     printf("                       ..............................................\n");
  161.     switch(_getch()){
  162.         case '1': adduser();
  163.                   break;
  164.         case '2': listuser();
  165.                   break;
  166.         case '3': edituser();
  167.                   break;
  168.         case '4': deluser();
  169.                   break;
  170.         case '5': searchuser();
  171.                   break;
  172.         case '6': booksection();
  173.                   break;
  174.         case '7': exit(0);
  175.                   break;
  176.         default:
  177.  
  178.             printf("\nEnter any key to try again.");
  179.             _getch();
  180. system("cls");
  181.     mainMenu();
  182.  
  183.     }
  184. }
  185.  
  186. // For Adding New users
  187. void adduser(){
  188.  
  189.  
  190.  
  191.     struct profile b;
  192.     struct profile g;
  193.      int i,j;
  194.      int o;
  195.      int userID;
  196.     FILE *f;
  197.     FILE *another;
  198.     f=fopen("frecord.txt","ab");
  199.     f=fopen("frecord.txt","rb");
  200.  
  201.     system("cls");
  202.     printf("\t\t\t...........................................\n");
  203.     printf("\t\t\t:\t\t[USER REGISTER]\t          :\n");
  204.      printf("\t\t\t...........................................\n");
  205.  
  206.  printf("\t\t\t\tEnter first and last name: ");
  207.     scanf("%s %s",b.firstname,b.lastname);
  208.       fflush(stdin);
  209. name1:
  210. strcat(b.firstname," ");
  211.    strcat(b.firstname,b.lastname);
  212.    for (j=0;b.firstname[j]!='\0';++j)//copying
  213.       {
  214.    b.name[j]=b.firstname[j];
  215.       }
  216.       b.name[j]='\0';
  217.  
  218.    for (j=0;b.name[j]!='\0';++j)
  219.       {
  220.       if (b.name[j]>='0' && b.name[j]<='9')
  221.       {
  222.           printf("\n");
  223.           printf("\t\t\t\tInvalid name\n");
  224.            printf("\t\t\t\tEnter name again: ");
  225.     scanf("%s %s",b.firstname,b.lastname);
  226.       fflush(stdin);
  227.       goto name1;
  228.           break;
  229.       }
  230.       }
  231.  
  232.     printf("\t\t\t\tEnter address: ");
  233.     scanf("%s",&b.address);
  234.     fflush(stdin);
  235.     printf("\t\t\t\tEnter phone number: ");
  236.     scanf("%lld",&b.phoneNumber);
  237.     fflush(stdin);
  238.     chck:
  239.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=99999999)
  240.     {
  241.  
  242.      printf("\t\t\t\tEnter UserID: ");
  243.     scanf("%d",&userID);
  244.     fflush(stdin);
  245.     fwrite(&b, sizeof(b), 1, f);
  246.  
  247.      another=fopen("frecord.txt","ab");
  248.      strcpy(g.name,b.name);
  249.         strcpy(g.address,b.address);
  250.         g.phoneNumber=b.phoneNumber;
  251.     while (fread(&b,sizeof(b),1,f)==1)
  252.     {
  253.         if (userID==b.userID)
  254.         {
  255.             fclose(f);
  256.             o=1;
  257.         }
  258.     }
  259.     if (o!=1)
  260.     {
  261.  
  262.         g.userID=userID;
  263.  
  264.         fwrite(&g, sizeof(g), 1, another);
  265.         printf("\t\t\tThe user id is available\n");
  266.         fclose(another);
  267.     }
  268.     else if (o==1){
  269.         printf("\t\t\tThe user ID already exists!!\n");
  270.         _getch();
  271.         mainMenu();
  272.     }
  273.  
  274.     }
  275.  
  276.  
  277.     else
  278.     {
  279.         printf("\n\t\t\t\tInvalid phone number!\n");
  280.         printf("\t\t\t\tEnter new phone number: ");
  281.     scanf("%lld",&b.phoneNumber);
  282.     fflush(stdin);
  283.     goto chck;
  284.     }
  285.  
  286.          printf("                        ............................................\n");
  287.  
  288.  
  289.  
  290.       printf("\nRecord Saved!\n");
  291.  
  292.           printf("\n\n");
  293.       printf("Would you like to add more user? [y/n]: ");
  294.             readd:
  295.       i=_getch();
  296.       if (i=='y')
  297.             {
  298.           adduser();
  299.                 }
  300.         if (i=='n')
  301.             {
  302.      printf("\nEnter any key to go back!");
  303.     _getch();
  304.     system("cls");
  305.     mainMenu();
  306.                 }
  307.                 else if(1)
  308.                 {
  309.                   goto readd;
  310.                 }
  311.  
  312. }
  313.  
  314. //Listing users profile
  315. void listuser(){
  316.  
  317.  
  318.     struct profile g;
  319.  
  320.     FILE *another;
  321.     another=fopen("frecord.txt","rb"); //binary read mode
  322.     system("cls");
  323.     if (another==NULL){
  324.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  325.         getch();
  326.         mainMenu();
  327.     }
  328.     printf("\t\t\t..................................................\n");
  329.     printf("\t\t\t:\t\t[LIST USERS PROFILE]             :\n");
  330.     printf("\t\t\t:................................................:\n");
  331.  
  332.     while(fread(&g,sizeof(g),1,another)==1){
  333.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",g.name,g.address,g.phoneNumber,g.userID);
  334.     }
  335. printf("............................................\n");
  336.     fclose(another);
  337.  
  338.     printf("\nEnter any key to go back!");
  339.     _getch();
  340.     system("cls");
  341.     mainMenu();
  342. }
  343.  
  344. //Editing profile
  345. void edituser(){
  346.     int id;
  347.     int found;
  348.    int e,j;
  349.  
  350.  
  351.     printf("                        ............................................\n");
  352.     printf("\t\t\t\t\t  [EDIT USER]\n\n");
  353.  
  354.  
  355.     struct profile b;
  356.  
  357.     FILE *fp;
  358.     FILE *ftemp;
  359.     fp = fopen("frecord.txt","rb");
  360.     ftemp = fopen("ftemprecord.txt","wb");
  361.      system("cls");
  362.     printf("\t\t\tEnter Users ID to modify: ");
  363.     scanf("%d",&id);
  364.     fflush(stdin);
  365.   printf("\n");
  366.     while(fread(&b,sizeof(b),1,fp)==1){
  367.             if(id!=b.userID)
  368.                 fwrite(&b,sizeof(b),1,ftemp);
  369.             if(id==b.userID){
  370.                 found = 1;
  371.             }
  372.     }
  373.     if (found == 1){
  374.   printf("\t\t\t\tEnter first and last name: ");
  375.     scanf("%s %s",b.firstname,b.lastname);
  376.       fflush(stdin);
  377. name1:
  378. strcat(b.firstname," ");
  379.    strcat(b.firstname,b.lastname);
  380.    for (j=0;b.firstname[j]!='\0';++j)
  381.       {
  382.    b.name[j]=b.firstname[j];
  383.       }
  384.       b.name[j]='\0';
  385.  
  386.    for (j=0;b.name[j]!='\0';++j)
  387.       {
  388.       if (b.name[j]>='0' && b.name[j]<='9')
  389.       {
  390.           printf("\n");
  391.           printf("\t\t\t\tInvalid name\n");
  392.            printf("\t\t\t\tEnter name again: ");
  393.     scanf("%s %s",b.firstname,b.lastname);
  394.       fflush(stdin);
  395.       goto name1;
  396.           break;
  397.       }
  398.       }
  399.     printf("\t\t\t\tEnter address: ");
  400.     scanf("%s",&b.address);
  401.     fflush(stdin);
  402.     printf("\t\t\t\tEnter phone number: ");
  403.     scanf("%lld",&b.phoneNumber);
  404.     fflush(stdin);
  405.     chck:
  406.     if (b.phoneNumber<=9999999999 && b.phoneNumber>=9999999)
  407.     {
  408.      printf("\t\t\t\tEnter UserID: ");
  409.     scanf("%d",&b.userID);
  410.     fflush(stdin);
  411.     }
  412.     else
  413.     {
  414.         printf("\n\t\t\t\tInvalid phone number!\n");
  415.         printf("\t\t\t\tEnter new phone number: ");
  416.     scanf("%lld",&b.phoneNumber);
  417.     fflush(stdin);
  418.     goto chck;
  419.     }
  420.         fwrite(&b,sizeof(b),1,ftemp);
  421.     }else if(found!=1){
  422.         printf("The contact does not exist!");
  423.     }
  424.  
  425.  
  426.  
  427.     fclose(fp);
  428.     fclose(ftemp);
  429.     remove("frecord.txt");
  430.     rename("ftemprecord.txt","frecord.txt");
  431.  
  432.     printf("\n\nEnter any key to go back!");
  433.     _getch();
  434.     system("cls");
  435.  
  436.     mainMenu();
  437.  
  438. }
  439.  
  440. //Searching profile
  441. void searchuser(){
  442.     int id;
  443.     int de,c;
  444.     struct profile b;
  445.  
  446.     FILE *fp;
  447.     fp=fopen("frecord.txt","rb");
  448.  
  449.     system("cls");
  450.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  451.     printf("\t\t\t...........................................\n");
  452.     printf("\t\t\t:\t\t[SEARCH USER]\t          :\n");
  453.     printf("\t\t\t:.........................................:\n\n");
  454.     printf("\t\t\tEnter Users ID to search: ");
  455.     scanf("%d",&id);
  456.     printf("\n\n");
  457.     fflush(stdin);
  458. printf("\n");
  459.     while (fread(&b,sizeof(b),1,fp)==1)
  460.     {
  461.         if (id==b.userID){
  462.  
  463.         printf("\n[%s Profile ID]\n",b.name);
  464.     printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
  465.     de=1;
  466. }
  467.     }
  468. if (de==1)
  469. {
  470.  
  471.     printf("\n\n");
  472.     printf("Would you like to search another user?[y/n]: ");
  473.      research:
  474.     c=_getch();
  475.     if (c=='y')
  476.     {
  477.         searchuser();
  478.             }
  479.             if (c=='n')
  480.             {
  481.                 printf("\n\n");
  482.               printf("\n\nEnter any key to go back!");
  483.  
  484.     _getch();
  485.     system("cls");
  486.     mainMenu();
  487.             }
  488.  
  489. }
  490.  
  491. if (de!=1)
  492. {
  493.     printf("\t\t\t\t\t*INVALID USER*");
  494.     printf("\n\nEnter any key to go back!");
  495.  
  496.     _getch();
  497.     system("cls");
  498.     mainMenu();
  499.  
  500. }
  501. fclose(fp);
  502. }
  503.  
  504.  
  505.  
  506.  
  507. //Deleting profile
  508. void deluser(){
  509.     char name[20];
  510.     int recordExists,id;
  511.  
  512.     system("cls");
  513.     fflush(stdin);
  514.  
  515.     struct profile b;
  516.  
  517.     FILE *fp;
  518.     FILE *ftemp;
  519.  
  520.     fp = fopen("frecord.txt","rb");
  521.  
  522.     ftemp = fopen("ftemprecord.txt","wb");
  523.  
  524.     printf("\t\t\t...........................................\n");
  525.     printf("\t\t\t:\t\t[DELETE USER]\t          :\n");
  526.     printf("\t\t\t:.........................................:\n\n");
  527.     printf("\t\t\tEnter Users ID to delete: ");
  528.     scanf("%d",&id);
  529.     fflush(stdin);
  530.     printf("\n");
  531.  
  532.     while (fread( &b, sizeof(b), 1, fp) == 1) {
  533.         if (id!=b.userID)
  534.  
  535.           fwrite(&b, sizeof(b), 1, ftemp);
  536.         if (id==b.userID)
  537.           recordExists = 1;
  538.     }
  539.  
  540.     fclose(fp);
  541.     fclose(ftemp);
  542.  
  543.     if(recordExists!=1){
  544.         printf("The contact does not exist!");
  545.     }else{
  546.         remove("frecord.txt");
  547.         rename("ftemprecord.txt", "frecord.txt");
  548.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  549.     }
  550.  
  551.     printf("\n\nEnter any key to go back!");
  552.     _getch();
  553.     system("cls");
  554.  
  555.     mainMenu();
  556. }
  557.  
  558. void booksection()
  559. {
  560.      system("cls");
  561.      system("color A");
  562.     printf("\t\t\t.............................................\n");
  563.     printf("\t\t\t:\t\t[BOOK SECTION]\t            :\n");
  564.     printf("\t\t\t:...........................................:\n\n");
  565.     printf("\t\t\t1.Add book\n\t\t\t2.List Book\n\t\t\t3.Edit book\n\t\t\t4.Delete Book\n\t\t\t5.Search Book\n\t\t\t6.Issue Book\n\t\t\t7.Exit\n\t\t\t8.Go back\n");
  566.     printf("\t\t\tPress (1-8)\n");
  567.     printf("                       ..............................................\n");
  568.  
  569.     switch(_getch()){
  570.         case '1': addbook();
  571.                   break;
  572.  
  573.         case '2':listbook();
  574.                   break;
  575.  
  576.         case '3':editbook();
  577.                   break;
  578.  
  579.         case '4':delbook();
  580.                   break;
  581.  
  582.         case '5':searchbook();
  583.                   break;
  584.  
  585.         case '6':issuemain();
  586.                   break;
  587.  
  588.         case '7':exit(0);
  589.                   break;
  590.  
  591.         case '8': mainMenu();
  592.                  break;
  593.         default:
  594.  
  595.             printf("\nEnter any key to try again.");
  596.             _getch();
  597. system("cls");
  598. booksection();
  599. }
  600. }
  601. //add books in the library
  602. void addbook()
  603. {
  604.  
  605.     char m[20];
  606.  
  607. struct books d;
  608.  
  609.     FILE *fb;
  610.     fb=fopen("booksection.txt","ab");
  611.     char bookname[50];
  612.     system("cls");
  613.     printf("\t\t\t...........................................\n");
  614.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  615.     printf("\t\t\t:.........................................:\n\n");
  616.     printf("\t\t\tEnter the name of the book to be added: ");
  617.    scanf("%s",d.bookname);
  618.  
  619.     printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
  620.     printf("\t\t\t\tEnter day: ");
  621.    scanf("%d",&d.day);
  622.     dete:
  623.    if (d.day>=0 && d.day<=32)
  624.     {
  625.          printf("\t\t\t\tEnter month: ");
  626.    scanf("%d",&d.month);
  627.     fflush(stdin);
  628.  
  629.     dete2:
  630.      if (d.month>=0 && d.month<=12)
  631.          {
  632.     printf("\t\t\t\tEnter year: ");
  633.     scanf("%d",&d.year);
  634.    fflush(stdin);
  635.    dete3:
  636.      if (d.year>2018 && d.day<2020)
  637.      {
  638.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  639.          scanf("%lld",&d.isbn);
  640.          fflush(stdin);
  641.          dete4:
  642.         if (d.isbn>9999 && d.isbn<100000)
  643.         {
  644.           printf("\t\t\t\tEnter quantity of book:");
  645.          scanf("%d",&d.quantity);
  646.         }
  647.         else{
  648.                 printf("\n");
  649.              printf("\t\t\t\tInvalid entry!!\n");
  650.     printf("\t\t\t\tEnter ISBN again: ");
  651.    scanf("%d",&d.isbn);
  652.           goto dete4;
  653.         }
  654.      }
  655.          else
  656.          {
  657.              printf("\n");
  658.              printf("\t\t\t\tInvalid entry!!\n");
  659.     printf("\t\t\t\tEnter year again: ");
  660.    scanf("%d",&d.year);
  661.    goto dete3;
  662.  
  663.     }
  664.          }
  665.  
  666.    else
  667. {
  668.      printf("\n");
  669.        printf("\t\t\t\tInvalid entry!!\n");
  670.     printf("\t\t\t\tEnter month again: ");
  671.    scanf("%d",&d.month);
  672.    goto dete2;
  673. }
  674.     }
  675.  
  676.     else{
  677.  printf("\n");
  678.        printf("\t\t\t\tInvalid entry!!\n");
  679.     printf("\t\t\t\tEnter day again: ");
  680.    scanf("%d",&d.day);
  681.    goto dete;
  682.     }
  683.  
  684.  
  685.  
  686.     printf("                        ............................................\n");
  687.     fwrite(&d,sizeof(d),1,fb);
  688.     fclose(fb);
  689.  
  690.     printf("\n\t\t\tRecord Saved\n\n!");
  691.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  692.     scanf("%s",m);
  693.     if (strcmp(m,"main")==0)
  694.     {
  695.         system("cls");
  696.         mainMenu();
  697.     }
  698.     else if (1)
  699.     {
  700.     system("cls");
  701.    booksection();
  702.     }
  703. }
  704.  
  705. void listbook()
  706. {
  707.  struct books d;
  708.  
  709.     FILE *fb;
  710.     fb=fopen("booksection.txt","r"); //binary read mode
  711.     system("cls");
  712.     if (fb==NULL){
  713.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  714.         getch();
  715.         booksection();
  716.     }
  717.     printf("\t\t\t..................................................\n");
  718.     printf("\t\t\t:\t\t   [LIST BOOKS]                  :\n");
  719.     printf("\t\t\t:................................................:\n");
  720.  
  721.     while(fread(&d,sizeof(d),1,fb)==1){
  722.     printf("\nBook Name: %s\nIssue date: %d/ %d/ %d\nBook ISBN: %lld\nBook Quantity: %d\n\n",d.bookname,d.day,d.month,d.year,d.isbn,d.quantity);
  723.     }
  724. printf("............................................\n");
  725.     fclose(fb);
  726.  
  727.     printf("\nEnter any key to go back!");
  728.     _getch();
  729.     system("cls");
  730.     booksection();
  731. }
  732. //edit book information
  733. void editbook(){
  734.     char m[20];
  735.     long long int bookid;
  736.     int bfound;
  737.    int be;
  738.  
  739.  
  740.     printf("                        ............................................\n");
  741.     printf("\t\t\t\t\t  [EDIT BOOK]\n\n");
  742.  
  743.  
  744.    struct books d;
  745.  
  746.     FILE *fb;
  747.     FILE *fbtemp;
  748.     fb=fopen("booksection.txt","r"); //binary read mode
  749.  
  750.     fbtemp = fopen("fbtemprecord.txt","w");
  751.      system("cls");
  752.     printf("\t\t\tEnter BOOK ISBN to modify: ");
  753.     scanf("%lld",&bookid);
  754.     fflush(stdin);
  755.   printf("\n");
  756.     while(fread(&d,sizeof(d),1,fb)==1){
  757.             if(bookid!=d.isbn)
  758.                 fwrite(&d,sizeof(d),1,fbtemp);
  759.             if(bookid==d.isbn){
  760.                 bfound = 1;
  761.             }
  762.     }
  763.     if (bfound == 1){
  764.     printf("\t\t\tEnter the name of the book to be added: ");
  765.     scanf("%s",d.bookname);
  766.     fflush(stdin);
  767.  printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
  768.     printf("\t\t\t\tEnter day: ");
  769.    scanf("%d",&d.day);
  770.     dete:
  771.    if (d.day>=0 && d.day<=32)
  772.     {
  773.          printf("\t\t\t\tEnter month: ");
  774.    scanf("%d",&d.month);
  775.     fflush(stdin);
  776.  
  777.     dete2:
  778.      if (d.month>=0 && d.month<=12)
  779.          {
  780.     printf("\t\t\t\tEnter year: ");
  781.     scanf("%d",&d.year);
  782.    fflush(stdin);
  783.    dete3:
  784.      if (d.year>2018 && d.day<2020)
  785.      {
  786.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  787.          scanf("%lld",&d.isbn);
  788.          fflush(stdin);
  789.          dete4:
  790.         if (d.isbn>9999 && d.isbn<100000)
  791.         {
  792.           printf("\t\t\t\tEnter quantity of book:");
  793.          scanf("%d",&d.quantity);
  794.         }
  795.         else{
  796.                 printf("\n");
  797.              printf("\t\t\t\tInvalid entry!!\n");
  798.     printf("\t\t\t\tEnter ISBN again: ");
  799.    scanf("%d",&d.isbn);
  800.           goto dete4;
  801.         }
  802.      }
  803.          else
  804.          {
  805.              printf("\n");
  806.              printf("\t\t\t\tInvalid entry!!\n");
  807.     printf("\t\t\t\tEnter year again: ");
  808.    scanf("%d",&d.year);
  809.    goto dete3;
  810.  
  811.     }
  812.          }
  813.  
  814.    else
  815. {
  816.      printf("\n");
  817.        printf("\t\t\t\tInvalid entry!!\n");
  818.     printf("\t\t\t\tEnter month again: ");
  819.    scanf("%d",&d.month);
  820.    goto dete2;
  821. }
  822.     }
  823.  
  824.     else{
  825.  printf("\n");
  826.        printf("\t\t\t\tInvalid entry!!\n");
  827.     printf("\t\t\t\tEnter day again: ");
  828.    scanf("%d",&d.day);
  829.    goto dete;
  830.     }
  831.  
  832.  
  833.         fwrite(&d,sizeof(d),1,fbtemp);
  834.     }else if(bfound!=1){
  835.         printf("\t\t\tThe book ID does not exist!");
  836.     }
  837.  
  838.  
  839.  
  840.     fclose(fb);
  841.     fclose(fbtemp);
  842.     remove("booksection.txt");
  843.     rename("fbtemprecord.txt","booksection.txt");
  844. printf("\n\n");
  845.    printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  846.     scanf("%s",m);
  847.     if (strcmp(m,"main")==0)
  848.     {
  849.         system("cls");
  850.         mainMenu();
  851.     }
  852.     else if (1)
  853.     {
  854.     system("cls");
  855.    booksection();
  856.     }
  857. }
  858.  
  859.  
  860.  
  861.  
  862.  
  863. void searchbook(){
  864.     char m[20];
  865.     long long int bid;
  866.     int bde,bc;
  867.     struct books d;
  868.  
  869.     FILE *fb;
  870.   fb=fopen("booksection.txt","r");
  871.  
  872.     system("cls");
  873.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  874.     printf("\t\t\t...........................................\n");
  875.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  876.     printf("\t\t\t:.........................................:\n\n");
  877.     printf("\t\t\tEnter BOOK ID to search: ");
  878.     scanf("%lld",&bid);
  879.     printf("\n\n");
  880.     fflush(stdin);
  881. printf("\n");
  882.     while (fread(&d,sizeof(d),1,fb)==1)
  883.     {
  884.         if (bid==d.isbn){
  885.  
  886.         printf("\n[%s Book Info]\n",d.bookname);
  887.    printf("\nBook Name: %s\nDate(dd/mm/yy): %lld/ %lld/ %lld\nBook ISBN: %lld\nBook Quantity: %d\n\n",d.bookname,d.day,d.month,d.year,d.isbn,d.quantity);
  888.     bde=1;
  889. }
  890.     }
  891. if (bde==1)
  892. {
  893.  
  894.     printf("\n\n");
  895.     printf("Would you like to search another book?[y/n]: ");
  896.      research:
  897.     bc=_getch();
  898.     if (bc=='y')
  899.     {
  900.         searchuser();
  901.             }
  902.             if (bc=='n')
  903.             {
  904.                 printf("\n\n");
  905.               printf("\n\nEnter any key to go back!");
  906.  
  907.     _getch();
  908.     system("cls");
  909.     booksection();
  910.             }
  911.             else if(1)
  912.             {
  913.                 goto research;
  914.             }
  915.  
  916. }
  917. if (bde!=1)
  918. {
  919.     printf("\t\t\t\t\t*INVALID BOOK ISBN*");
  920.     printf("\n\n");
  921.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  922.     scanf("%s",m);
  923.     if (strcmp(m,"main")==0)
  924.     {
  925.         system("cls");
  926.         mainMenu();
  927.     }
  928.     else if (1)
  929.     {
  930.     system("cls");
  931.    booksection();
  932.     }
  933. }
  934. fclose(fb);
  935. }
  936.  
  937.  
  938.  
  939. void delbook(){
  940.     char m[20];
  941.     char bname[20];
  942.     int brecordExists;
  943.     long long int bid;
  944.  
  945.     system("cls");
  946.     fflush(stdin);
  947.  
  948.     struct books d;
  949.  
  950.     FILE *fb;
  951.     FILE *fbtemp;
  952.  
  953.    fb=fopen("booksection.txt","r");
  954.     fbtemp = fopen("fbtemprecord.txt","w");
  955.  
  956.     printf("\t\t\t...........................................\n");
  957.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  958.     printf("\t\t\t:.........................................:\n\n");
  959.     printf("\t\t\tEnter Book ISBN to delete: ");
  960.     scanf("%lld",&bid);
  961.     fflush(stdin);
  962.     printf("\n");
  963.  
  964.     while (fread( &d, sizeof(d), 1, fb) == 1) {
  965.         if (bid!=d.isbn)
  966.           fwrite(&d, sizeof(d), 1, fbtemp);
  967.         if (bid==d.isbn)
  968.           brecordExists = 1;
  969.     }
  970.  
  971.     fclose(fb);
  972.     fclose(fbtemp);
  973.  
  974.     if(brecordExists!=1){
  975.         printf("\t\t\tThe book does not exist!");
  976.     }else{
  977.         remove("booksection.txt");
  978.         rename("fbtemprecord.txt", "booksection.txt");
  979.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  980.     }
  981. printf("\n\n");
  982.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  983.     scanf("%s",m);
  984.     if (strcmp(m,"main")==0)
  985.     {
  986.         system("cls");
  987.         mainMenu();
  988.     }
  989.     else if (1)
  990.     {
  991.     system("cls");
  992.    booksection();
  993.     }
  994. }
  995.  
  996. void issuemain()
  997. {
  998.  system("color E");//yellow
  999.     system("cls");
  1000.     printf("\t\t\t...........................................\n");
  1001.     printf("\t\t\t:\t\t[ISSUE BOOKS]\t          :\n");
  1002.     printf("\t\t\t:.........................................:\n");
  1003.     printf("\n\n\n\t\t\t1.Borrow book\n\t\t\t2.View Issued Books\n\t\t\t2.Return book\n\t\t\t4.Fine payment\n\t\t\t5.Search book\n\t\t\t6.Exit\n\t\t\t7.Go back");
  1004.     printf("\t\t\tPress (1-7)\n");
  1005.     printf("                       ..............................................\n");
  1006.     switch(_getch()){
  1007.         case '1': borrowbook();
  1008.         break;
  1009.  
  1010.         case '2':viewissuedbook();
  1011.         break;
  1012.  
  1013.         case '6':exit(0);
  1014.         break;
  1015.  
  1016.         case '7':booksection();
  1017.                 break;
  1018.  
  1019.         default:
  1020.  
  1021.             printf("\nEnter any key to try again.");
  1022.             _getch();
  1023. system("cls");
  1024.     mainMenu();
  1025.  
  1026.     }
  1027. }
  1028.  
  1029.  
  1030.  
  1031. void borrowbook()
  1032. {
  1033.  
  1034.     struct profile g;
  1035.     struct books e;
  1036.     struct books d;
  1037.     int quantity;
  1038.     FILE *another,*fb;
  1039.     FILE *issue;
  1040.     int m,k,j,i;
  1041.     issue=fopen("issuebook.txt","wb");
  1042.     another=fopen("frecord.txt","rb");
  1043.     fb=fopen("booksection.txt","rb");
  1044.  
  1045.     system("cls");
  1046.     printf("\t\t\t\t[BORROW BOOKS]\n\n");
  1047.     printf("\t\t\tEnter reader's ID: ");
  1048.  
  1049.     scanf("%d",&userid1);
  1050.  
  1051.  
  1052.  
  1053. while(fread(&g,sizeof(g),1,another)==1)
  1054. {
  1055.     if (userid1==g.userID)
  1056.     {
  1057. e.userid=userid1;
  1058. m=1;
  1059.     }
  1060. }
  1061.  
  1062.  
  1063. if (m!=1)
  1064. {
  1065.    printf("\t\t\tNot found");
  1066.    _getch();
  1067.    issuemain();
  1068. }
  1069. else
  1070. {
  1071.     printf("\t\t\tEnter the number of books you want to borrow: ");
  1072.        scanf("%d",&quantity);
  1073.        e.quantity=quantity;
  1074.  
  1075.        if (quantity>0 && quantity<4)
  1076.        {
  1077.            e.quantity=quantity;
  1078.            for (i=0;i<quantity;i++)
  1079.            {
  1080.  
  1081.                printf("\t\t\tEnter ISBN of the book(5 digits): ");
  1082.       scanf("%lld",&isbn1);
  1083.  
  1084.  
  1085.     while(fread(&d,sizeof(d),1,fb)==1)
  1086.    {
  1087.  
  1088.      if (isbn1==d.isbn)
  1089.      {
  1090.           e.isbn=isbn1;
  1091.  
  1092.          k=1;
  1093.  
  1094.      }
  1095.    }
  1096.  
  1097.    if (k!=1)
  1098.    {
  1099.        printf("\t\t\tBook ISBN not found!!");
  1100.        _getch();
  1101.        issuemain();
  1102.    }
  1103.  
  1104.  else if (k==1)
  1105.    {
  1106.   printf("\t\t\t %d number of books of ISBN %d is available.\n",d.quantity,isbn1);
  1107.  
  1108.    }
  1109.  
  1110.    }
  1111.  
  1112.  
  1113.        }
  1114.        else
  1115.        {
  1116.            printf("\t\t\tYou can't have more than three books!!\n");
  1117.            _getch();
  1118.            issuemain();
  1119.        }
  1120.  
  1121.  
  1122.      printf("\t\t\tEnter the issue date:\n ");
  1123.     printf("\t\t\t\tEnter day: ");
  1124.    scanf("%d",&e.issueday);
  1125.     dete:
  1126.    if (e.issueday>=0 && e.issueday<=32)
  1127.     {
  1128.          printf("\t\t\t\tEnter month: ");
  1129.    scanf("%d",&e.issuemonth);
  1130.     fflush(stdin);
  1131.  
  1132.     dete2:
  1133.      if (e.issuemonth>=0 && e.issuemonth<=12)
  1134.          {
  1135.     printf("\t\t\t\tEnter year: ");
  1136.     scanf("%d",&e.issueyear);
  1137.    fflush(stdin);
  1138.    dete3:
  1139.      if (e.issueyear>2018 && e.issueyear <2020)
  1140.      {
  1141.          e.submitday=e.issueday;
  1142.           e.submitmonth=e.issuemonth+1;
  1143.           if (e.submitmonth>12)
  1144.           {
  1145.               e.submityear=e.issueyear+1;
  1146.               e.submitmonth=e.submitmonth-12;
  1147.           }
  1148.           else{
  1149.             e.submityear=e.issueyear;
  1150.           }
  1151.  
  1152.          printf("\t\t\t\tReturn date:%d/ %d/ %d ",e.submitday,e.submitmonth,e.submityear );
  1153.           fwrite(&e,sizeof(e),1,issue);
  1154.    fclose(issue);
  1155.          _getch();
  1156.          issuemain();
  1157.  
  1158.      }
  1159.  
  1160.          else
  1161.          {
  1162.              printf("\n");
  1163.              printf("\t\t\t\tInvalid entry!!\n");
  1164.     printf("\t\t\t\tEnter year again: ");
  1165.    scanf("%d",&e.issueyear);
  1166.    goto dete3;
  1167.  
  1168.     }
  1169.          }
  1170.  
  1171.    else
  1172. {
  1173.      printf("\n");
  1174.        printf("\t\t\t\tInvalid entry!!\n");
  1175.     printf("\t\t\t\tEnter month again: ");
  1176.    scanf("%d",&e.issuemonth);
  1177.    goto dete2;
  1178. }
  1179.     }
  1180.  
  1181.     else{
  1182.  printf("\n");
  1183.        printf("\t\t\t\tInvalid entry!!\n");
  1184.     printf("\t\t\t\tEnter day again: ");
  1185.    scanf("%d",&e.issueday);
  1186.    goto dete;
  1187.     }
  1188.  
  1189.  
  1190. }
  1191. fclose(fb);
  1192.  
  1193. fclose(another);
  1194.  
  1195.  
  1196. }
  1197.  
  1198.  
  1199.  
  1200.  
  1201. void viewissuedbook()
  1202. {
  1203.  
  1204.     struct books e;
  1205.     FILE *issue;
  1206.  
  1207.     issue=fopen("issuebook.txt","rb");
  1208.     system("cls");
  1209.     if (issue==NULL){
  1210.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1211.         getch();
  1212.         issuemain();
  1213.     }
  1214.     printf("\t\t\t..................................................\n");
  1215.     printf("\t\t\t:\t\t[LIST ISSUED BOOKS]             :\n");
  1216.     printf("\t\t\t:................................................:\n");
  1217.  
  1218.     while(fread(&e,sizeof(e),1,issue)==1){
  1219.     printf("\nUser ID: %d\nBook Quantity: %d\nIssue Date [dd/mm/yy]: %d/ %d/ %d\nReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.userid,e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1220.  
  1221.     }
  1222.  
  1223. printf("............................................\n");
  1224.     fclose(issue);
  1225.  
  1226.     printf("\nEnter any key to go back!");
  1227.     _getch();
  1228.     system("cls");
  1229.     issuemain();
  1230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement