Advertisement
Sheyshya

Complete lms

May 11th, 2019
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 40.79 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. #include<time.h>
  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.     char category[30];
  33. };
  34. int userid1;
  35. long long int isbn1;
  36.  
  37. //Profjile Functions List
  38. void mainMenu();
  39. void adduser();
  40. void deluser();
  41. void edituser();
  42. void listuser();
  43. void searchuser();
  44. void adminlogin();
  45.  
  46. //book functions list
  47. void booksection();
  48. void addbook();
  49. void listbook();
  50. void searchbook();
  51. void delbook();
  52. void editbook();
  53. void viewissuedbook();
  54. void issuemain();
  55. void borrowbook();
  56. void returnbook();
  57. void category();
  58. void searchissue();
  59. void delissuebook();
  60. //main function.
  61. int main()
  62. {
  63.     system("color f");  //sets system color to bright white.
  64.   adminlogin();
  65.    return 0;
  66. }
  67.  
  68. void adminlogin()   //sets up admin login window.
  69. {
  70.     int i=0;
  71.     char aa[20],ch;
  72.     char password[30];
  73.     char username[30];
  74.     start:
  75.    printf("\t\t\t..............................................\n");
  76.     printf("\t\t\t\t\t[ADMIN LOGIN]                \n\n");
  77.     printf("\t\t\tEnter your username: ");
  78.     scanf("%s",username);
  79.      printf("\t\t\tEnter your password: ");
  80.     while(ch!=13)
  81.    {
  82.  ch=_getch();
  83.  
  84.  if(ch!=13){
  85.  putch('*');
  86.  password[i] = ch;
  87.  i++;
  88.  }
  89.    }
  90.    password[i] = '\0';
  91.  
  92.  
  93.     if(strcmp(username,"a")==0){
  94.  
  95.    if(strcmp(password,"b")==0)
  96.    {
  97.        printf("\n\n");
  98.        char loading[]="\t\t\t\tloading.....................................!!\n";
  99.         while(loading[i]!='\0')
  100.     {
  101.         Sleep(15);
  102.         printf("%c",loading[i]);
  103.         i++;
  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.  
  606.  
  607.     char m[20];
  608.  
  609. struct books d;
  610.  
  611.     FILE *fb;
  612.     fb=fopen("booksection.txt","ab");
  613.     char bookname[50];
  614. int s;
  615.     system("cls");
  616.     printf("\t\t\t...........................................\n");
  617.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  618.     printf("\t\t\t:.........................................:\n\n");
  619.     printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  620.  
  621. printf("\t\t 1. Computer\n");
  622.  
  623. printf("\t\t 2. Science\n");
  624.  
  625. printf("\t\t 3. Medical\n");
  626.  
  627. printf("\t\t 4. Language\n");
  628.  
  629. printf("\t\t 5. Arts and literature\n");
  630.  
  631. printf("\t\t 6. History\n");
  632.  
  633. printf("\t\t 7. Back \n");
  634. printf("\t\tEnter your choice: ");
  635.     scanf("%d",&s);
  636.  
  637.  
  638. printf("Enter your choice:");
  639. switch(s)
  640. {
  641.     case 1: strcpy(d.category,"Computer");
  642.     goto add;
  643.     break;
  644.  
  645.     case 2:strcpy(d.category,"Science");
  646.     goto add;
  647.     break;
  648.  
  649.        case 3:strcpy(d.category,"Medical");
  650.     goto add;
  651.     break;
  652.        case 4:strcpy(d.category,"Language");
  653.     goto add;
  654.     break;
  655.        case 5:strcpy(d.category,"Arts and literature");
  656.     goto add;
  657.     break;
  658.        case 6:strcpy(d.category,"History");
  659.     goto add;
  660.     break;
  661.        case 7:
  662.     booksection();
  663.     break;
  664.     default: printf("\t\tInvalid choice\n");
  665.       booksection();
  666.       break;
  667.  
  668. }
  669.  
  670.  
  671. add:
  672. system("cls");
  673.     printf("\t\t\t...........................................\n");
  674.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  675.     printf("\t\t\t:.........................................:\n\n");
  676.     printf("\t\t\tEnter the name of the book to be added: ");
  677. scanf("%s",d.bookname);
  678. fflush(stdin);
  679.  
  680.     printf("\t\t\t\tEnter issue date(dd/mm/yy):\n ");
  681.     printf("\t\t\t\tEnter day: ");
  682.    scanf("%d",&d.day);
  683.    fflush(stdin);
  684.     dete:
  685.    if (d.day>0 && d.day<=30)
  686.     {
  687.          printf("\t\t\t\tEnter month: ");
  688.    scanf("%d",&d.month);
  689.     fflush(stdin);
  690.  
  691.     dete2:
  692.      if (d.month>0 && d.month<=12)
  693.          {
  694.     printf("\t\t\t\tEnter year: ");
  695.     scanf("%d",&d.year);
  696.    fflush(stdin);
  697.    dete3:
  698.      if (d.year>2018 && d.day<2020)
  699.      {
  700.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  701.          scanf("%lld",&d.isbn);
  702.          fflush(stdin);
  703.          dete4:
  704.         if (d.isbn>9999 && d.isbn<100000)
  705.         {
  706.           printf("\t\t\t\tEnter quantity of book:");
  707.          scanf("%d",&d.quantity);
  708.  
  709.         }
  710.         else{
  711.                 printf("\n");
  712.              printf("\t\t\t\tInvalid entry!!\n");
  713.     printf("\t\t\t\tEnter ISBN again: ");
  714.    scanf("%d",&d.isbn);
  715.           goto dete4;
  716.         }
  717.      }
  718.          else
  719.          {
  720.              printf("\n");
  721.              printf("\t\t\t\tInvalid entry!!\n");
  722.     printf("\t\t\t\tEnter year again: ");
  723.    scanf("%d",&d.year);
  724.    goto dete3;
  725.  
  726.     }
  727.          }
  728.  
  729.    else
  730. {
  731.      printf("\n");
  732.        printf("\t\t\t\tInvalid entry!!\n");
  733.     printf("\t\t\t\tEnter month again: ");
  734.    scanf("%d",&d.month);
  735.    goto dete2;
  736. }
  737.     }
  738.  
  739.     else{
  740.  printf("\n");
  741.        printf("\t\t\t\tInvalid entry!!\n");
  742.     printf("\t\t\t\tEnter day again: ");
  743.    scanf("%d",&d.day);
  744.    goto dete;
  745.     }
  746.  
  747.  
  748.  
  749.     printf("                        ............................................\n");
  750.     fwrite(&d,sizeof(d),1,fb);
  751.     fclose(fb);
  752.  
  753.     printf("\n\t\t\tRecord Saved\n\n!");
  754.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  755.     scanf("%s",m);
  756.     if (strcmp(m,"main")==0)
  757.     {
  758.         system("cls");
  759.         mainMenu();
  760.     }
  761.     else if (1)
  762.     {
  763.     system("cls");
  764.    booksection();
  765.     }
  766. }
  767.  
  768. void listbook()
  769. {
  770.  struct books d;
  771.  
  772.     FILE *fb;
  773.     fb=fopen("booksection.txt","r"); //binary read mode
  774.     system("cls");
  775.     if (fb==NULL){
  776.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  777.         getch();
  778.         booksection();
  779.     }
  780.     printf("\t\t\t..................................................\n");
  781.     printf("\t\t\t:\t\t   [LIST BOOKS]                  :\n");
  782.     printf("\t\t\t:................................................:\n");
  783.  
  784.     while(fread(&d,sizeof(d),1,fb)==1){
  785.     printf("\nCategory: %s\nBook Name: %s\nIssue date: %d/ %d/ %d\nBook ISBN: %lld\nBook Quantity: %d\n\n",d.category,d.bookname,d.day,d.month,d.year,d.isbn,d.quantity);
  786.     }
  787. printf("............................................\n");
  788.     fclose(fb);
  789.  
  790.     printf("\nEnter any key to go back!");
  791.     _getch();
  792.     system("cls");
  793.     booksection();
  794. }
  795. //edit book information
  796. void editbook(){
  797.     char m[20];
  798.     long long int bookid;
  799.     int bfound;
  800.    int be;
  801. int s;
  802.  
  803.     printf("                        ............................................\n");
  804.     printf("\t\t\t\t\t  [EDIT BOOK]\n\n");
  805.  
  806.  
  807.    struct books d;
  808.  
  809.     FILE *fb;
  810.     FILE *fbtemp;
  811.     fb=fopen("booksection.txt","r"); //binary read mode
  812.  
  813.     fbtemp = fopen("fbtemprecord.txt","w");
  814.      system("cls");
  815.     printf("\t\t\tEnter BOOK ISBN to modify: ");
  816.     scanf("%lld",&bookid);
  817.     fflush(stdin);
  818.   printf("\n");
  819.     while(fread(&d,sizeof(d),1,fb)==1){
  820.             if(bookid!=d.isbn)
  821.                 fwrite(&d,sizeof(d),1,fbtemp);
  822.             if(bookid==d.isbn){
  823.                 bfound = 1;
  824.             }
  825.     }
  826.     if (bfound == 1){
  827.  
  828.      printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  829.  
  830. printf("\t\t 1. Computer\n");
  831.  
  832. printf("\t\t 2. Science\n");
  833.  
  834. printf("\t\t 3. Medical\n");
  835.  
  836. printf("\t\t 4. Language\n");
  837.  
  838. printf("\t\t 5. Arts and literature\n");
  839.  
  840. printf("\t\t 6. History\n");
  841.  
  842. printf("\t\t 7. Back \n");
  843. printf("\t\tEnter your choice: ");
  844.     scanf("%d",&s);
  845.  
  846.  
  847. printf("Enter your choice:");
  848. switch(s)
  849. {
  850.     case 1: strcpy(d.category,"Computer");
  851.     goto add;
  852.     break;
  853.  
  854.     case 2:strcpy(d.category,"Science");
  855.     goto add;
  856.     break;
  857.  
  858.        case 3:strcpy(d.category,"Medical");
  859.     goto add;
  860.     break;
  861.        case 4:strcpy(d.category,"Language");
  862.     goto add;
  863.     break;
  864.        case 5:strcpy(d.category,"Arts and literature");
  865.     goto add;
  866.     break;
  867.        case 6:strcpy(d.category,"History");
  868.     goto add;
  869.     break;
  870.        case 7:
  871.     booksection();
  872.     break;
  873.     default: printf("\t\tInvalid choice\n");
  874.       booksection();
  875.       break;
  876.  
  877. }
  878.  
  879.  
  880. add:
  881. system("cls");
  882.     printf("\t\t\t...........................................\n");
  883.     printf("\t\t\t:\t\t[ADD BOOKS]\t          :\n");
  884.     printf("\t\t\t:.........................................:\n\n");
  885.  
  886.  
  887.     printf("\t\t\tEnter the name of the book to be added: ");
  888.     scanf("%s",d.bookname);
  889.     fflush(stdin);
  890.  printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
  891.     printf("\t\t\t\tEnter day: ");
  892.    scanf("%d",&d.day);
  893.     dete:
  894.    if (d.day>0 && d.day<=30)
  895.     {
  896.          printf("\t\t\t\tEnter month: ");
  897.    scanf("%d",&d.month);
  898.     fflush(stdin);
  899.  
  900.     dete2:
  901.      if (d.month>0 && d.month<=12)
  902.          {
  903.     printf("\t\t\t\tEnter year: ");
  904.     scanf("%d",&d.year);
  905.    fflush(stdin);
  906.    dete3:
  907.      if (d.year>2018 && d.day<2020)
  908.      {
  909.          printf("\t\t\t\tEnter Book ISBN(5 digits):");
  910.          scanf("%lld",&d.isbn);
  911.          fflush(stdin);
  912.          dete4:
  913.         if (d.isbn>9999 && d.isbn<100000)
  914.         {
  915.           printf("\t\t\t\tEnter quantity of book:");
  916.          scanf("%d",&d.quantity);
  917.         }
  918.         else{
  919.                 printf("\n");
  920.              printf("\t\t\t\tInvalid entry!!\n");
  921.     printf("\t\t\t\tEnter ISBN again: ");
  922.    scanf("%d",&d.isbn);
  923.           goto dete4;
  924.         }
  925.      }
  926.          else
  927.          {
  928.              printf("\n");
  929.              printf("\t\t\t\tInvalid entry!!\n");
  930.     printf("\t\t\t\tEnter year again: ");
  931.    scanf("%d",&d.year);
  932.    goto dete3;
  933.  
  934.     }
  935.          }
  936.  
  937.    else
  938. {
  939.      printf("\n");
  940.        printf("\t\t\t\tInvalid entry!!\n");
  941.     printf("\t\t\t\tEnter month again: ");
  942.    scanf("%d",&d.month);
  943.    goto dete2;
  944. }
  945.     }
  946.  
  947.     else{
  948.  printf("\n");
  949.        printf("\t\t\t\tInvalid entry!!\n");
  950.     printf("\t\t\t\tEnter day again: ");
  951.    scanf("%d",&d.day);
  952.    goto dete;
  953.     }
  954.  
  955.  
  956.         fwrite(&d,sizeof(d),1,fbtemp);
  957.     }else if(bfound!=1){
  958.         printf("\t\t\tThe book ID does not exist!");
  959.     }
  960.  
  961.  
  962.  
  963.     fclose(fb);
  964.     fclose(fbtemp);
  965.     remove("booksection.txt");
  966.     rename("fbtemprecord.txt","booksection.txt");
  967. printf("\n\n");
  968.    printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  969.     scanf("%s",m);
  970.     if (strcmp(m,"main")==0)
  971.     {
  972.         system("cls");
  973.         mainMenu();
  974.     }
  975.     else if (1)
  976.     {
  977.     system("cls");
  978.    booksection();
  979.     }
  980. }
  981.  
  982.  
  983.  
  984.  
  985.  
  986. void searchbook(){
  987.     char m[20];
  988.     long long int bid;
  989.     int bde,bc;
  990.     struct books d;
  991. int s;
  992.     FILE *fb;
  993.   fb=fopen("booksection.txt","r");
  994.  
  995.     system("cls");
  996.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  997.     printf("\t\t\t...........................................\n");
  998.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  999.     printf("\t\t\t:.........................................:\n\n");
  1000.     printf("\t\t\tSearch by category or ISBN?\n");
  1001.     printf("\n\t\t\t1.Category\n\t\t\t2.ISBN\n");
  1002.     printf("\t\t\tEnter you choice: ");
  1003.     scanf("%d",&s);
  1004.  
  1005.       switch(s)
  1006.       {
  1007.           case 1: category();
  1008.           break;
  1009.  
  1010.           case 2:goto srch;
  1011.           break;
  1012.           default:printf("\t\t\tInvalid choice!!");
  1013.           _getch();
  1014.               booksection();
  1015.           break;
  1016.       }
  1017.  
  1018.     srch:
  1019.           system("cls");
  1020.     printf("\t\t\tEnter BOOK ID to search: ");
  1021.     scanf("%lld",&bid);
  1022.     printf("\n\n");
  1023.     fflush(stdin);
  1024. printf("\n");
  1025.     while (fread(&d,sizeof(d),1,fb)==1)
  1026.     {
  1027.         if (bid==d.isbn){
  1028.  
  1029.         printf("\n\t\t\t[%s Book Info]\n",d.bookname);
  1030.   printf("\n\t\t\tBook Name: %s\n\t\t\tDate(dd/mm/yy): %lld/ %lld/ %lld\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.day,d.month,d.year,d.isbn,d.quantity);
  1031.     bde=1;
  1032. }
  1033.     }
  1034. if (bde==1)
  1035. {
  1036.  
  1037.     printf("\n\n");
  1038.     printf("\t\t\tWould you like to search another book?[y/n]: ");
  1039.      research:
  1040.     bc=_getch();
  1041.     if (bc=='y')
  1042.     {
  1043.         searchbook();
  1044.             }
  1045.             if (bc=='n')
  1046.             {
  1047.                 printf("\n\n");
  1048.               printf("\n\nEnter any key to go back!");
  1049.  
  1050.     _getch();
  1051.     system("cls");
  1052.     booksection();
  1053.             }
  1054.             else if(1)
  1055.             {
  1056.                 goto research;
  1057.             }
  1058.  
  1059. }
  1060. if (bde!=1)
  1061. {
  1062.     printf("\t\t\t\t\t*INVALID BOOK ISBN*");
  1063.     printf("\n\n");
  1064.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1065.     scanf("%s",m);
  1066.     if (strcmp(m,"main")==0)
  1067.     {
  1068.         system("cls");
  1069.         mainMenu();
  1070.     }
  1071.     else if (1)
  1072.     {
  1073.     system("cls");
  1074.    booksection();
  1075.     }
  1076. }
  1077. fclose(fb);
  1078. }
  1079.  
  1080. void category()
  1081. {
  1082.  
  1083.  
  1084.     char m[20];
  1085.     char cat[30];
  1086.     long long int bid;
  1087.     int bde,bc;
  1088.     struct books d;
  1089. int s;
  1090.     FILE *fb;
  1091.   fb=fopen("booksection.txt","r");
  1092.  
  1093.     system("cls");
  1094.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  1095.     printf("\t\t\t...........................................\n");
  1096.     printf("\t\t\t:\t\t[SEARCH BOOK]\t          :\n");
  1097.     printf("\t\t\t:.........................................:\n\n");
  1098.  
  1099.       printf("\t\t\t\t[SELECT CATEGORY]\n\n");
  1100.  
  1101. printf("\t\t 1. Computer\n");
  1102.  
  1103. printf("\t\t 2. Science\n");
  1104.  
  1105. printf("\t\t 3. Medical\n");
  1106.  
  1107. printf("\t\t 4. Language\n");
  1108.  
  1109. printf("\t\t 5. Arts and literature\n");
  1110.  
  1111. printf("\t\t 6. History\n");
  1112.  
  1113. printf("\t\t 7. Back \n");
  1114.  
  1115.  
  1116.  
  1117.     printf("\t\tEnter category to search: ");
  1118.     scanf("%s",cat);
  1119.         fflush(stdin);
  1120.  
  1121. printf("\n");
  1122.     while (fread(&d,sizeof(d),1,fb)==1)
  1123.     {
  1124.         if (strcmp(cat,d.category)==0){
  1125.  
  1126.         printf("\n\t\t\t[%s Book Info]\n",d.bookname);
  1127.    printf("\n\t\t\tBook Name: %s\n\t\t\tDate(dd/mm/yy): %lld/ %lld/ %lld\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.day,d.month,d.year,d.isbn,d.quantity);
  1128.     bde=1;
  1129. }
  1130.     }
  1131. if (bde==1)
  1132. {
  1133.  
  1134.     printf("\n\n");
  1135.     printf("\t\t\tWould you like to search another book?[y/n]: ");
  1136.      research:
  1137.     bc=_getch();
  1138.     if (bc=='y')
  1139.     {
  1140.         searchuser();
  1141.             }
  1142.             if (bc=='n')
  1143.             {
  1144.                 printf("\n\n");
  1145.               printf("\n\nEnter any key to go back!");
  1146.  
  1147.     _getch();
  1148.     system("cls");
  1149.     booksection();
  1150.             }
  1151.             else if(1)
  1152.             {
  1153.                 goto research;
  1154.             }
  1155.  
  1156. }
  1157. if (bde!=1)
  1158. {
  1159.     printf("\t\t\t\t\t*Book Not Found!!");
  1160.     printf("\n\n");
  1161.     printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1162.     scanf("%s",m);
  1163.     if (strcmp(m,"main")==0)
  1164.     {
  1165.         system("cls");
  1166.         mainMenu();
  1167.     }
  1168.     else if (1)
  1169.     {
  1170.     system("cls");
  1171.    booksection();
  1172.     }
  1173. }
  1174. fclose(fb);
  1175.  
  1176. }
  1177.  
  1178. void delbook(){
  1179.     char m[20];
  1180.     char bname[20];
  1181.     int brecordExists;
  1182.     long long int bid;
  1183.  
  1184.     system("cls");
  1185.     fflush(stdin);
  1186.  
  1187.     struct books d;
  1188.  
  1189.     FILE *fb;
  1190.     FILE *fbtemp;
  1191.  
  1192.    fb=fopen("booksection.txt","r");
  1193.     fbtemp = fopen("fbtemprecord.txt","w");
  1194.  
  1195.     printf("\t\t\t...........................................\n");
  1196.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  1197.     printf("\t\t\t:.........................................:\n\n");
  1198.     printf("\t\t\tEnter Book ISBN to delete: ");
  1199.     scanf("%lld",&bid);
  1200.     fflush(stdin);
  1201.     printf("\n");
  1202.  
  1203.     while (fread( &d, sizeof(d), 1, fb) == 1) {
  1204.         if (bid!=d.isbn)
  1205.           fwrite(&d, sizeof(d), 1, fbtemp);
  1206.         if (bid==d.isbn)
  1207.           brecordExists = 1;
  1208.     }
  1209.  
  1210.     fclose(fb);
  1211.     fclose(fbtemp);
  1212.  
  1213.     if(brecordExists!=1){
  1214.         printf("\t\t\tThe book does not exist!");
  1215.     }else{
  1216.         remove("booksection.txt");
  1217.         rename("fbtemprecord.txt", "booksection.txt");
  1218.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  1219.     }
  1220. printf("\n\n");
  1221.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1222.     scanf("%s",m);
  1223.     if (strcmp(m,"main")==0)
  1224.     {
  1225.         system("cls");
  1226.         mainMenu();
  1227.     }
  1228.     else if (1)
  1229.     {
  1230.     system("cls");
  1231.    booksection();
  1232.     }
  1233. }
  1234.  
  1235. void issuemain()
  1236. {
  1237.  system("color E");//yellow
  1238.     system("cls");
  1239.     printf("\t\t\t...........................................\n");
  1240.     printf("\t\t\t:\t\t[ISSUE BOOKS]\t          :\n");
  1241.     printf("\t\t\t:.........................................:\n");
  1242.     printf("\n\n\n\t\t\t1.Borrow book\n\t\t\t2.View Issued Books\n\t\t\t3.Return book\n\t\t\t4.Search book\n\t\t\t5.Remove Issued Books\n\t\t\t6.Exit\n\t\t\t7.Go back\n");
  1243.     printf("\t\t\tPress (1-6)\n");
  1244.     printf("                       ..............................................\n");
  1245.     switch(_getch()){
  1246.         case '1': borrowbook();
  1247.         break;
  1248.  
  1249.         case '2':viewissuedbook();
  1250.         break;
  1251.  
  1252.         case '3':returnbook();
  1253.         break;
  1254.  
  1255.         case '4':searchissue();
  1256.         break;
  1257.  
  1258.         case '5':delissuebook();
  1259.         break;
  1260.  
  1261.         case '6': exit(0);
  1262.         break;
  1263.  
  1264.         case '7':booksection();
  1265.                 break;
  1266.  
  1267.         default:
  1268.  
  1269.             printf("\nEnter any key to try again.");
  1270.             _getch();
  1271. system("cls");
  1272.     mainMenu();
  1273.  
  1274.     }
  1275. }
  1276.  
  1277.  
  1278.  
  1279. void borrowbook()
  1280. {
  1281.  
  1282.  
  1283.     struct profile g;
  1284.     struct books e;
  1285.     struct books d;
  1286.     char borrow[20];
  1287.     int quantity,quantity1,n1;
  1288.     FILE *another,*fb;
  1289.     FILE *issue;
  1290.     int m,k,j,i,n;
  1291.     issue=fopen("issuebook.txt","ab");
  1292.     another=fopen("frecord.txt","rb");
  1293.     fb=fopen("booksection.txt","rb");
  1294.  
  1295.  
  1296.     system("cls");
  1297.     printf("\t\t\t\t[BORROW BOOKS]\n\n");
  1298.     printf("\t\t\tEnter reader's ID: ");
  1299.  
  1300.     scanf("%d",&userid1);
  1301.  
  1302.  
  1303.  
  1304. while(fread(&g,sizeof(g),1,another)==1)
  1305. {
  1306.     if (userid1==g.userID)
  1307.     {
  1308. e.userid=userid1;
  1309.  
  1310. m=1;
  1311.     }
  1312. }
  1313.  
  1314.  
  1315. if (m!=1)
  1316. {
  1317.    printf("\t\t\tNot found");
  1318.    _getch();
  1319.    issuemain();
  1320. }
  1321. else
  1322. {
  1323.  
  1324.        printf("\t\t\tHave you borrowed the book previously?: ");
  1325.        scanf("%s",borrow);
  1326.        if (strcmp(borrow,"yes")==0)
  1327.        {
  1328.            printf("\t\t\tHow many books did you borrow?: ");
  1329.            scanf("%d", &n1);
  1330.            if (n1>3)
  1331.            {
  1332.                printf("\t\t\tError! Cant borrow more than 3 books!!");
  1333.                _getch();
  1334.                issuemain();
  1335.            }
  1336.            else if (n1==0)
  1337.            {
  1338.             printf("\t\t\t0 books can't be borrowed!!\n");
  1339.            _getch();
  1340.            issuemain();
  1341.            }
  1342.            else
  1343.            {
  1344.  
  1345.  
  1346.            printf("\t\t\tEnter the number of books you want to borrow: ");
  1347.        scanf("%d",&quantity);
  1348.  
  1349.        quantity1=quantity+n1;
  1350.        if (quantity==0)
  1351.        {
  1352.            printf("\t\t\t0 books can't be borrowed!!\n");
  1353.            _getch();
  1354.            issuemain();
  1355.        }
  1356.  
  1357.            }
  1358.  
  1359.        }
  1360.  
  1361.  
  1362.        else if (strcmp(borrow,"no")==0)
  1363.        {
  1364.        printf("\t\t\tEnter the number of books you want to borrow: ");
  1365.        scanf("%d",&quantity);
  1366.        quantity1=quantity;
  1367.         if (quantity==0)
  1368.        {
  1369.            printf("\t\t\t0 books can't be borrowed!!\n");
  1370.            _getch();
  1371.            issuemain();
  1372.        }
  1373.  
  1374.  
  1375.  
  1376.        }
  1377.  
  1378.  else if (1)
  1379.        {
  1380.            printf("\t\t\tInvalid entry!\n");
  1381.            _getch();
  1382.            issuemain();
  1383.        }
  1384.  
  1385.        if (quantity1>0 && quantity1<4)
  1386.        {
  1387.            e.quantity=quantity;
  1388. start1:
  1389.            for (i=0;i<quantity;i++)
  1390.            {
  1391.  
  1392.                printf("\t\t\tEnter ISBN of the book(5 digits): ");
  1393.       scanf("%lld",&isbn1);
  1394.  
  1395.  
  1396.     while(fread(&d,sizeof(d),1,fb)==1)
  1397.    {
  1398.  
  1399.      if (isbn1==d.isbn)
  1400.      {
  1401.           e.isbn=isbn1;
  1402.  
  1403.          k=1;
  1404.  
  1405.      }
  1406.    }
  1407.  
  1408.    if (k!=1)
  1409.    {
  1410.        printf("\t\t\tBook ISBN not found!!");
  1411.        _getch();
  1412.        issuemain();
  1413.    }
  1414.  
  1415.  else if (k==1)
  1416.    {
  1417.  
  1418.   printf("\t\t\tHow many books of this ISBN do you want to borrow?: ");
  1419.   scanf("%d",&n);
  1420.  
  1421. if (n>d.quantity)
  1422. {
  1423.     printf("\t\t\tInvalid entry!!\n");
  1424.     _getch();
  1425.     issuemain();
  1426. }
  1427. if (n==quantity)
  1428. {
  1429.     goto start;
  1430. }
  1431. if (n==1)
  1432. {
  1433.     quantity=quantity-1;
  1434.  goto start1;
  1435. }
  1436. else{
  1437.     printf("\t\t\tInvalid entry!!\n");
  1438. _getch();
  1439. issuemain();
  1440. }
  1441.    }
  1442.    }
  1443.        }
  1444.  
  1445.  
  1446.        else
  1447.        {
  1448.            printf("\t\t\tYou can't have more than three books!!\n");
  1449.            _getch();
  1450.            issuemain();
  1451.        }
  1452.  
  1453. start:
  1454.      printf("\t\t\tEnter the issue date:\n ");
  1455.     printf("\t\t\t\tEnter day: ");
  1456.    scanf("%d",&e.issueday);
  1457.     dete:
  1458.    if (e.issueday>0 && e.issueday<=30)
  1459.     {
  1460.          printf("\t\t\t\tEnter month: ");
  1461.    scanf("%d",&e.issuemonth);
  1462.     fflush(stdin);
  1463.  
  1464.     dete2:
  1465.      if (e.issuemonth>0 && e.issuemonth<=12)
  1466.          {
  1467.     printf("\t\t\t\tEnter year: ");
  1468.     scanf("%d",&e.issueyear);
  1469.    fflush(stdin);
  1470.    dete3:
  1471.      if (e.issueyear>2018 && e.issueyear <2020)
  1472.      {
  1473.          e.submitday=e.issueday;
  1474.           e.submitmonth=e.issuemonth+1;
  1475.           if (e.submitmonth>12)
  1476.           {
  1477.               e.submityear=e.issueyear+1;
  1478.               e.submitmonth=e.submitmonth-12;
  1479.           }
  1480.           else{
  1481.             e.submityear=e.issueyear;
  1482.           }
  1483.  
  1484.          printf("\t\t\t\tReturn date:%d/ %d/ %d ",e.submitday,e.submitmonth,e.submityear );
  1485.           fwrite(&e,sizeof(e),1,issue);
  1486.    fclose(issue);
  1487.          _getch();
  1488.          issuemain();
  1489.  
  1490.      }
  1491.  
  1492.          else
  1493.          {
  1494.              printf("\n");
  1495.              printf("\t\t\t\tInvalid entry!!\n");
  1496.     printf("\t\t\t\tEnter year again: ");
  1497.    scanf("%d",&e.issueyear);
  1498.    goto dete3;
  1499.  
  1500.     }
  1501.          }
  1502.  
  1503.    else
  1504. {
  1505.      printf("\n");
  1506.        printf("\t\t\t\tInvalid entry!!\n");
  1507.     printf("\t\t\t\tEnter month again: ");
  1508.    scanf("%d",&e.issuemonth);
  1509.    goto dete2;
  1510. }
  1511.     }
  1512.  
  1513.     else{
  1514.  printf("\n");
  1515.        printf("\t\t\t\tInvalid entry!!\n");
  1516.     printf("\t\t\t\tEnter day again: ");
  1517.    scanf("%d",&e.issueday);
  1518.    goto dete;
  1519.     }
  1520.  
  1521.  
  1522. }
  1523. fclose(fb);
  1524.  
  1525. fclose(another);
  1526.  
  1527.  
  1528. }
  1529.  
  1530.  
  1531.  
  1532.  
  1533. void viewissuedbook()
  1534. {
  1535.  
  1536.     struct books e;
  1537.     FILE *issue;
  1538.  
  1539.     issue=fopen("issuebook.txt","rb");
  1540.     system("cls");
  1541.     if (issue==NULL){
  1542.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1543.         getch();
  1544.         issuemain();
  1545.     }
  1546.     printf("\t\t\t..................................................\n");
  1547.     printf("\t\t\t:\t\t[LIST ISSUED BOOKS]             :\n");
  1548.     printf("\t\t\t:................................................:\n");
  1549.  
  1550.     while(fread(&e,sizeof(e),1,issue)==1){
  1551.     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);
  1552.  
  1553.     }
  1554.  
  1555. printf("............................................\n");
  1556.     fclose(issue);
  1557.  
  1558.     printf("\nEnter any key to go back!");
  1559.     _getch();
  1560.     system("cls");
  1561.     issuemain();
  1562. }
  1563.  
  1564.  
  1565.  
  1566. void returnbook()
  1567. {
  1568.      struct books e;
  1569.     FILE *issue;
  1570.     int i,j;
  1571.     int quantity,quantity1;
  1572.     int day,month,year;
  1573.     int fine1;
  1574.    issue=fopen("issuebook.txt","rb");
  1575.     if (issue==NULL){
  1576.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1577.         getch();
  1578.         issuemain();
  1579.     }
  1580. system("cls");
  1581.      printf("\t\t\t..................................................\n");
  1582.     printf("\t\t\t:\t\t[RETURN BOOKS]             :\n");
  1583.     printf("\t\t\t:................................................:\n");
  1584.  
  1585.    printf("\t\t\tEnter USER ID: ");
  1586.    scanf("%d",&userid1);
  1587.    while(fread(&e,sizeof(e),1,issue)==1){
  1588.         if (userid1==e.userid)
  1589.         {
  1590.            i=1;
  1591.         }
  1592.  
  1593.     }
  1594.     if (i==1)
  1595.     {
  1596.         printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1597.         printf("\t\t\t\tEnter the quantity of book returned: ");
  1598.         scanf("%d",&quantity);
  1599.         if (quantity<e.quantity)
  1600.         {
  1601.             quantity1=e.quantity-quantity;
  1602.             printf("\t\t\t\t%d books not returned!!\n",quantity1);
  1603.  
  1604.             quantity=quantity1*200;
  1605.  
  1606.             goto start;
  1607.         }
  1608.         else if (quantity==e.quantity)
  1609.         {
  1610.            printf("\t\t\t\tAll the books are returned!!\n");
  1611.            quantity=0;
  1612.            goto start;
  1613.         }
  1614.         else if (quantity>e.quantity)
  1615.         {
  1616.             printf("\t\t\t\tInvalid quantity!!\n");
  1617.             _getch();
  1618.             issuemain();
  1619.         }
  1620.         start:
  1621.         printf("\t\t\t\tEnter the date on which the user returned the book:\n");
  1622.         printf("\t\t\t\tEnter day: ");
  1623.    scanf("%d",&day);
  1624.     dete:
  1625.    if (day>0 && day<=30)
  1626.     {
  1627.          printf("\t\t\t\tEnter month: ");
  1628.    scanf("%d",&month);
  1629.     fflush(stdin);
  1630.     if (e.submitmonth==12)
  1631.     {
  1632.         month=12+month;
  1633.         goto start1;
  1634.     }
  1635.  
  1636.     dete2:
  1637.      if (month>0 && month<=12)
  1638.          {
  1639.     printf("\t\t\t\tEnter year: ");
  1640.     scanf("%d",&year);
  1641.    fflush(stdin);
  1642.    dete3:
  1643.      if (year>2018 && day<2021)
  1644.      {
  1645.  
  1646.  
  1647.         if (((month==e.issuemonth)||(month==e.submitmonth))&&((year==e.issueyear)||(year==e.submityear)))
  1648.         {
  1649.             printf("\t\t\t\tBook is returned on time!!\n");
  1650.             _getch();
  1651.           issuemain();
  1652.         }
  1653.  
  1654.  start1:
  1655.  if ((month>e.submitmonth)||(year>e.submityear))
  1656. {
  1657.     j=day-e.submitday;
  1658.     year=year-e.submityear;
  1659.     day=365*year;
  1660.     month=month-e.submitmonth;
  1661.     day=day+30*month+j;
  1662.     fine1=2*day+quantity;
  1663.     printf("\t\t\t\tThe user has to pay Rs %d.",fine1);
  1664.     _getch();
  1665. issuemain();
  1666.  
  1667. }
  1668.  
  1669.      }
  1670.          else
  1671.          {
  1672.              printf("\n");
  1673.              printf("\t\t\t\tInvalid entry!!\n");
  1674.     printf("\t\t\t\tEnter year again: ");
  1675.    scanf("%d",&year);
  1676.    goto dete3;
  1677.  
  1678.     }
  1679.          }
  1680.  
  1681.    else
  1682. {
  1683.      printf("\n");
  1684.        printf("\t\t\t\tInvalid entry!!\n");
  1685.     printf("\t\t\t\tEnter month again: ");
  1686.    scanf("%d",&month);
  1687.    goto dete2;
  1688. }
  1689.     }
  1690.  
  1691.     else{
  1692.  printf("\n");
  1693.        printf("\t\t\t\tInvalid entry!!\n");
  1694.     printf("\t\t\t\tEnter day again: ");
  1695.    scanf("%d",&day);
  1696.    goto dete;
  1697.     }
  1698.  
  1699.  
  1700.     }
  1701.     else
  1702.     {
  1703.         printf("\t\t\tUser not found!\n");
  1704.         _getch();
  1705.         issuemain();
  1706.     }
  1707.  
  1708. fclose(issue);
  1709. }
  1710.  
  1711.  
  1712. void searchissue(){
  1713.     int id;
  1714.     int de,c;
  1715.  
  1716.    struct books e;
  1717.     FILE *issue;
  1718.     int i,j;
  1719.     int quantity,quantity1;
  1720.     int day,month,year;
  1721.     int fine1;
  1722.    issue=fopen("issuebook.txt","rb");
  1723.     if (issue==NULL){
  1724.         printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
  1725.         getch();
  1726.         issuemain();
  1727.     }
  1728.  
  1729.     system("cls");
  1730.     printf("\t\t\t\t   LIBRARY MANAGEMENT SYSTEM\n\n\n");
  1731.     printf("\t\t\t...........................................\n");
  1732.     printf("\t\t\t:\t\t[SEARCH USER]\t          :\n");
  1733.     printf("\t\t\t:.........................................:\n\n");
  1734.     printf("\t\t\tEnter Users ID to search: ");
  1735.     scanf("%d",&id);
  1736.     printf("\n\n");
  1737.     fflush(stdin);
  1738. printf("\n");
  1739.     while (fread(&e,sizeof(e),1,issue)==1)
  1740.     {
  1741.         if (id==e.userid){
  1742.    printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
  1743.     de=1;
  1744. }
  1745.     }
  1746. if (de==1)
  1747. {
  1748.  
  1749.     printf("\n\n");
  1750.     printf("Would you like to search another user?[y/n]: ");
  1751.      research:
  1752.     c=_getch();
  1753.     if (c=='y')
  1754.     {
  1755.         searchuser();
  1756.             }
  1757.             if (c=='n')
  1758.             {
  1759.                 printf("\n\n");
  1760.               printf("\n\nEnter any key to go back!");
  1761.  
  1762.     _getch();
  1763.     system("cls");
  1764.     mainMenu();
  1765.             }
  1766.  
  1767. }
  1768.  
  1769. if (de!=1)
  1770. {
  1771.     printf("\t\t\t\t\t*INVALID USER*");
  1772.     printf("\n\nEnter any key to go back!");
  1773.  
  1774.     _getch();
  1775.     system("cls");
  1776.     mainMenu();
  1777.  
  1778. }
  1779. fclose(issue);
  1780. }
  1781.  
  1782.  
  1783. void delissuebook(){
  1784.     char m[20];
  1785.     char bname[20];
  1786.     int brecordExists;
  1787.     long long int bid;
  1788.  
  1789.     system("cls");
  1790.     fflush(stdin);
  1791.  
  1792.     struct books e;
  1793.  
  1794.     FILE *fb;
  1795.     FILE *fbtemp;
  1796.  
  1797.    fb=fopen("issuebook.txt","r");
  1798.     fbtemp = fopen("fbtempissue.txt","w");
  1799.  
  1800.     printf("\t\t\t...........................................\n");
  1801.     printf("\t\t\t:\t\t[DELETE BOOK]\t          :\n");
  1802.     printf("\t\t\t:.........................................:\n\n");
  1803.     printf("\t\t\tEnter UserID to delete: ");
  1804.     scanf("%lld",&bid);
  1805.     fflush(stdin);
  1806.     printf("\n");
  1807.  
  1808.     while (fread( &e, sizeof(e), 1, fb) == 1) {
  1809.         if (bid!=e.userid)
  1810.           fwrite(&e, sizeof(e), 1, fbtemp);
  1811.         if (bid==e.userid)
  1812.           brecordExists = 1;
  1813.     }
  1814.  
  1815.     fclose(fb);
  1816.     fclose(fbtemp);
  1817.  
  1818.     if(brecordExists!=1){
  1819.         printf("\t\t\tThe user does not exist!");
  1820.     }else{
  1821.         remove("issuebook.txt");
  1822.         rename("fbtempissue.txt", "issuebook.txt");
  1823.         printf("\t\tRECORD DELETED SUCCESSFULLY.");
  1824.     }
  1825. printf("\n\n");
  1826.   printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
  1827.     scanf("%s",m);
  1828.     if (strcmp(m,"main")==0)
  1829.     {
  1830.         system("cls");
  1831.         mainMenu();
  1832.     }
  1833.     else if (1)
  1834.     {
  1835.     system("cls");
  1836.    issuemain();
  1837.     }
  1838. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement