Advertisement
Guest User

Calvin

a guest
Feb 5th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 28.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. struct hr
  7. {
  8.     char emp_ID[20];
  9.     char emp_name[20];
  10.     char password[30];
  11. };
  12.  
  13. struct academicleader
  14. {
  15.     char emp_ID[20];
  16.     char emp_name[20];
  17.     char password[30];
  18. };
  19.  
  20. struct lecturer
  21. {
  22.     char emp_ID[20];
  23.     char emp_name[20];
  24.     char password[30];
  25. };
  26.  
  27. struct yearlyleaves
  28. {
  29.     int days;
  30. };
  31.  
  32. struct holidays
  33.  
  34. {
  35.     char description[50];
  36.     int dd, mm, yy;
  37. };
  38.  
  39.  
  40. struct policies
  41.  
  42. {
  43.     char count[5];
  44.     char policies[100];
  45. };
  46.  
  47. struct leaveapplication
  48.  
  49. {
  50.     char emp_ID[20];
  51.     char emp_name[20];
  52.     char subject[50];
  53.     char status[50];
  54.     int dd, mm, yy;
  55. };
  56.  
  57.  
  58. int date();
  59. int loginHR();
  60. int loginAL();
  61. int loginL();
  62. char registrationHR();
  63. char registrationAL();
  64. char registrationL();
  65. void HRmenu();
  66. void lecturerview();
  67. void loginmenu();
  68. void lecturerdetails();
  69. int deleterecord();
  70. int updaterecordL();
  71. int searchrecordL();
  72. int yearlyleaves();
  73. int updateholidays();
  74. int updatepolicies();
  75. void policiesmenu();
  76. void registrationmenu();
  77. void academicleadermenu();
  78. int viewholidays();
  79. void lecturermenu();
  80. int viewFAQ();
  81. int leaveapplication();
  82. int statusview();
  83. int changestatus();
  84.  
  85.  
  86. /* */
  87.  
  88.  
  89. int main()
  90. {
  91.     printf("========================================================================================\n");
  92.     printf("\t\tWelcome to ABC Employees Leave Management System\n");
  93.     printf("=========================================================================================\n\n");
  94.     date();
  95.     printf("---------------------------------------------------------------------------------------------");
  96.     printf("\nPlease Login Into the System to Proceed.\n\n");
  97.  
  98.  
  99.     int options;
  100.  
  101. login:
  102.     while (1)
  103.     {
  104.         printf("1. Login\n");
  105.         printf("2. Exit\n");
  106.  
  107.         fflush(stdin);
  108.         printf("\nInput an option: ");
  109.         scanf("%d", &options);
  110.  
  111.  
  112.         switch (options)
  113.         {
  114.         case 1:   loginmenu();
  115.             break;
  116.  
  117.         case 2:   exit(1);
  118.             break;
  119.  
  120.         default:   printf("\nError input. Choose only between 1 and 2.\n");
  121.             goto login;
  122.         }
  123.         break;
  124.  
  125.     }
  126.  
  127.     return 0;
  128. }
  129.  
  130.  
  131. void loginmenu()
  132. {
  133.     printf("========================================================================================\n");
  134.     printf("\t\tWELCOME TO LOGIN!!\n");
  135.     printf("=========================================================================================\n\n");
  136.     date();
  137.     printf("---------------------------------------------------------------------------------------------");
  138.  
  139.     int options;
  140.  
  141.     printf("\n1. Human Resource\n");
  142.     printf("2. Academic Leader\n");
  143.     printf("3. Lecturer\n");
  144.     printf("4. Exit\n");
  145.  
  146. choice:
  147.     while (1)
  148.     {
  149.  
  150.         fflush(stdin);
  151.         printf("\nEnter a number: ");
  152.         scanf("%d", &options);
  153.  
  154.         switch (options)
  155.         {
  156.  
  157.         case 1:   loginHR();
  158.             break;
  159.  
  160.         case 2:   loginAL();
  161.             break;
  162.  
  163.         case 3:   loginL();
  164.             break;
  165.         case 4: exit(1);
  166.             break;
  167.  
  168.         default:   printf("\nError input!! Choose only from 1 to 4.\n");
  169.             goto choice;
  170.         }
  171.         break;
  172.     }
  173.     return;
  174. }
  175.  
  176. void HRmenu()
  177.  
  178. {
  179.     printf("========================================================================================\n");
  180.     printf("\t\tWELCOME TO HR MENU!!\n");
  181.     printf("=========================================================================================\n\n");
  182.     date();
  183.     printf("---------------------------------------------------------------------------------------------");
  184.  
  185.     int options;
  186.  
  187.     printf("\n1. Register New User\n");
  188.     printf("2. Lecturer Details\n");
  189.     printf("3. Lecturer Leave Status\n");
  190.     printf("4. Upload Leaves\n");
  191.     printf("5. Upload Public and University Holidays\n");
  192.     printf("6. Update University Leaves Policies\n");
  193.     printf("7. Exit\n");
  194.  
  195.  
  196.  
  197. choice:
  198.     while (1)
  199.     {
  200.  
  201.         fflush(stdin);
  202.         printf("\nChoose an option: ");
  203.         scanf("%d", &options);
  204.  
  205.         switch (options)
  206.         {
  207.         case 1:   registrationmenu();
  208.             break;
  209.  
  210.         case 2:   lecturerdetails();
  211.             break;
  212.  
  213.         case 3:   statusview();
  214.             break;
  215.  
  216.         case 4:   yearlyleaves();
  217.             break;
  218.  
  219.         case 5:   updateholidays();
  220.             break;
  221.  
  222.         case 6:   policiesmenu();
  223.             break;
  224.  
  225.         case 7: exit(1);
  226.             break;
  227.  
  228.         default:   printf("Error input!! Choose only from 1 to 7\n");
  229.             goto choice;
  230.  
  231.         }
  232.         break;
  233.     }
  234.     return;
  235. }
  236.  
  237. void registrationmenu()
  238.  
  239. {
  240.     printf("========================================================================================\n");
  241.     printf("\t\tWELCOME TO REGISTRATION MENU!!\n");
  242.     printf("=========================================================================================\n\n");
  243.     date();
  244.     printf("---------------------------------------------------------------------------------------------");
  245.  
  246.     int options;
  247.  
  248.     printf("\n1. Register Academic Leader\n");
  249.     printf("2. Register Lecturer\n");
  250.     printf("3. Exit\n");
  251.  
  252. choice:
  253.     while (1)
  254.     {
  255.         fflush(stdin);
  256.         printf("\nEnter an option: ");
  257.         scanf("%d", &options);
  258.  
  259.         switch (options)
  260.         {
  261.         case 1:   registrationAL();
  262.             break;
  263.  
  264.         case 2:   registrationL();
  265.             break;
  266.  
  267.         case 3: exit(1);
  268.             break;
  269.  
  270.         default:  printf("Error input. Choose only from 1 to 3.\n");
  271.             goto choice;
  272.  
  273.         }
  274.         break;
  275.     }
  276.     return;
  277. }
  278.  
  279. void lecturerdetails()
  280. {
  281.     printf("========================================================================================\n");
  282.     printf("\t\tWELCOME TO LECTURER PROFILE EDITS!!\n");
  283.     printf("=========================================================================================\n\n");
  284.     date();
  285.     printf("---------------------------------------------------------------------------------------------");
  286.  
  287.     int options;
  288.  
  289.     printf("1. Search Lecturer Details\n");
  290.     printf("2. View Lecturer Details\n");
  291.     printf("3. Modify Lecturer Details\n");
  292.     printf("4. Delete Lecturer Details\n");
  293.     printf("5. Exit\n");
  294.  
  295. choice:
  296.     while (1) {
  297.         fflush(stdin);
  298.         printf("\nChoose an option: ");
  299.         scanf("%d", &options);
  300.  
  301.         switch (options)
  302.         {
  303.         case 1:   searchrecordL();
  304.             break;
  305.  
  306.         case 2:   lecturerview();
  307.             break;
  308.  
  309.         case 3:   updaterecordL();
  310.             break;
  311.  
  312.         case 4:   deleterecord();
  313.             break;
  314.            
  315.         case 5: exit(1);
  316.             break;
  317.  
  318.         default:  printf("Error input. Choose only from 1 to 5.\n");
  319.             goto choice;
  320.         }
  321.         break;
  322.     }
  323.     return;
  324. }
  325.  
  326.  
  327. void policiesmenu()
  328.  
  329. {
  330.     printf("========================================================================================\n");
  331.     printf("\t\tWELCOME TO POLICIES MENU\n");
  332.     printf("=========================================================================================\n\n");
  333.     date();
  334.     printf("---------------------------------------------------------------------------------------------");
  335.  
  336.     int options;
  337.    
  338.     printf("\n1. Add New Policy\n");
  339.     printf("2. Update Policy\n");
  340.     printf("3. Exit\n");
  341.  
  342.  
  343. choice:
  344.     while (1) {
  345.         fflush(stdin);
  346.         printf("\nChoose an option: ");
  347.         scanf("%d", &options);
  348.  
  349.         switch (options)
  350.         {
  351.  
  352.         case 1:   universitypolicies();
  353.             break;
  354.  
  355.         case 2:   updatepolicies();
  356.             break;
  357.  
  358.         case 3: exit(1);
  359.             break;
  360.  
  361.         default:   printf("Error input. Choose from 1 to 3.\n");
  362.             goto choice;
  363.         }
  364.         break;
  365.     }
  366.     return;
  367. }
  368.  
  369. void academicleadermenu()
  370.  
  371. {
  372.     printf("========================================================================================\n");
  373.     printf("\t\tWELCOME TO ACADEMIC LEADER MENU!!\n");
  374.     printf("=========================================================================================\n\n");
  375.     date();
  376.     printf("---------------------------------------------------------------------------------------------");
  377.  
  378.     int options;
  379.  
  380.     printf("1. View Lecturer's Leave Application\n");
  381.     printf("2. Approve/Reject Lecturer's Application\n");
  382.     printf("3. Delete Leave Application\n");
  383.     printf("4. View Public and University Holidays\n");
  384.     printf("5. View FAQ about Lecturer Leaves\n");
  385.     printf("6. Exit\n");
  386.  
  387. choice:
  388.     while (1)
  389.     {
  390.         fflush(stdin);
  391.         printf("\nChoose an option: ");
  392.         scanf("%d", &options);
  393.  
  394.         switch (options)
  395.         {
  396.         case 1:   statusview();
  397.             break;
  398.  
  399.         case 2:   changestatus();
  400.             break;
  401.  
  402.         case 3:   deleterecord();
  403.             break;
  404.  
  405.         case 4:   viewholidays();
  406.             break;
  407.  
  408.         case 5:   viewFAQ();
  409.             break;
  410.  
  411.         case 6: exit(1);
  412.             break;
  413.  
  414.         default:   printf("Error input. Choose from 1 to 6. \n");
  415.             goto choice;
  416.  
  417.  
  418.         }
  419.         break;
  420.     }
  421.     return;
  422. }
  423.  
  424. void lecturermenu()
  425.  
  426. {
  427.     printf("========================================================================================\n");
  428.     printf("\t\tWELCOME TO LECTURER MENU!!\n");
  429.     printf("=========================================================================================\n\n");
  430.     date();
  431.     printf("---------------------------------------------------------------------------------------------");
  432.  
  433.     int options;
  434.  
  435.    
  436.     printf("\n1. Apply for Leave\n");
  437.     printf("2. Check Status of Leave Application\n");
  438.     printf("3. View Public and University Holidays\n");
  439.     printf("4. View FAQ about Lecturer Leaves\n");
  440.     printf("5. Exit\n");
  441.  
  442. choice:
  443.     while (1)
  444.     {
  445.         fflush(stdin);
  446.         printf("\nChoose an option: ");
  447.         scanf("%d", &options);
  448.  
  449.         switch (options)
  450.         {
  451.         case 1:   leaveapplication();
  452.             break;
  453.  
  454.         case 2:   statusview();
  455.             break;
  456.  
  457.         case 3:   viewholidays();
  458.             break;
  459.  
  460.         case 4:   viewFAQ();
  461.             break;
  462.  
  463.         case 5: exit(1);
  464.             break;
  465.  
  466.         default:   printf("\Error input. Choose from 1 to 5\n");
  467.             goto choice;
  468.  
  469.         }
  470.         break;
  471.     }
  472.     return;
  473. }
  474.  
  475. int date()
  476. {
  477.     time_t currentTime;
  478.     time(&currentTime);
  479.     printf("\t\t\t\t\t\t\t%s\n", ctime(&currentTime));
  480.  
  481.     return 0;
  482. }
  483.  
  484. char registrationHR()
  485. {
  486.  
  487.     system("cls");
  488.     printf("========================================================================================\n");
  489.     printf("\t\tWELCOME TO HR REGISTRATION!!\n");
  490.     printf("=========================================================================================\n\n");
  491.     date();
  492.     printf("---------------------------------------------------------------------------------------------");
  493.  
  494.     struct hr record;
  495.  
  496.     printf("Enter the UserID: ");
  497.     scanf(" %s", record.emp_ID);
  498.  
  499.     printf("\nEnter the username: ");
  500.     scanf(" %s", record.emp_name);
  501.  
  502.     printf("\nEnter the password: ");
  503.     scanf(" %s", record.password);
  504.  
  505.  
  506.     FILE *qa;
  507.  
  508.     // open file for writing
  509.     qa = fopen("HR.txt", "a");
  510.     if (qa == NULL)
  511.     {
  512.         fprintf(stderr, "\nEOF\n");
  513.         exit(1);
  514.     }
  515.  
  516.  
  517.     // write struct to file
  518.     fwrite(&record, sizeof(struct hr), 1, qa);
  519.     fclose(qa);
  520.  
  521.     if (fwrite != 0)
  522.         printf("\nRecord Successfully!!\n");
  523.     else
  524.         printf("ERROR!!\n");
  525.  
  526.  
  527.     return 0;
  528.  
  529. }
  530.  
  531. int loginHR()
  532. {
  533.     //system("cls");
  534.     printf("========================================================================================\n");
  535.     printf("\t\tWELCOME TO HR LOGIN!!\n");
  536.     printf("=========================================================================================\n\n");
  537.     date();
  538.     printf("---------------------------------------------------------------------------------------------");
  539.  
  540.     char emp_name[50];
  541.     char password[50];
  542.     int flag = 0;
  543.  
  544.     FILE *qb;
  545.     struct hr record;
  546.  
  547.  
  548.     printf("\nPlease Enter your Username, Password to Proceed\n\n");
  549.     printf("\n\nUsername: ");
  550.     scanf(" %s", emp_name);
  551.     printf("\nPassword: ");
  552.     scanf(" %s", password);
  553.  
  554.  
  555.  
  556.  
  557.     qb = fopen("HR.txt", "r");
  558.     if (qb == NULL)
  559.     {
  560.         fprintf(stderr, "\nEOF\n");
  561.         exit(1);
  562.     }
  563.  
  564.     // read file contents till end of file
  565.  
  566.     while (fread(&record, sizeof(struct hr), 1, qb)) {
  567.         if (strcmp(emp_name, record.emp_name) == 0 && strcmp(password, record.password) == 0)
  568.         {
  569.             HRmenu();
  570.             flag = 1;
  571.             break;
  572.         }
  573.     }
  574.  
  575.     fclose(qb);
  576.  
  577.     if (!flag)
  578.     {
  579.         printf("Incorrect data entered. Please try again!\n");
  580.         loginHR();
  581.     }
  582.     return 0;
  583.  
  584. }
  585.  
  586. char registrationAL()
  587. {
  588.  
  589.     system("cls");
  590.     printf("========================================================================================\n");
  591.     printf("\t\tWELOME TO ACADEMIC LEADER REGISTRATION!!\n");
  592.     printf("=========================================================================================\n\n");
  593.     date();
  594.     printf("---------------------------------------------------------------------------------------------");
  595.  
  596.     struct academicleader record;
  597.  
  598.     printf("Enter the UserID: ");
  599.     scanf(" %s", record.emp_ID);
  600.  
  601.     printf("\nEnter the username: ");
  602.     scanf(" %s", record.emp_name);
  603.  
  604.     printf("\nEnter the password: ");
  605.     scanf(" %s", record.password);
  606.  
  607.     FILE *qa;
  608.  
  609.     // open file for writing
  610.     qa = fopen("AL.txt", "a");
  611.     if (qa == NULL)
  612.     {
  613.         fprintf(stderr, "\nEOF\n");
  614.         exit(1);
  615.     }
  616.  
  617.  
  618.     // write struct to file
  619.     fwrite(&record, sizeof(struct academicleader), 1, qa);
  620.     fclose(qa);
  621.  
  622.     if (fwrite != 0)
  623.         printf("\nRecord Success!! !\n");
  624.     else
  625.         printf("ERROR!! !\n");
  626.  
  627.  
  628.     return 0;
  629.  
  630. }
  631.  
  632. int loginAL()
  633. {
  634.     //system("cls");
  635.     printf("========================================================================================\n");
  636.     printf("\t\tWELCOME TO ACADEMIC LEADER LOGIN!!\n");
  637.     printf("=========================================================================================\n\n");
  638.     date();
  639.     printf("---------------------------------------------------------------------------------------------");
  640.  
  641.     char emp_name[50];
  642.     char password[50];
  643.     int flag = 0;
  644.  
  645.     FILE *qb;
  646.     struct academicleader record;
  647.  
  648.  
  649.     printf("\nPlease Enter your Username, Password and Position to Proceed\n\n");
  650.     printf("\n\nUsername: ");
  651.     scanf(" %s", emp_name);
  652.     printf("\nPassword: ");
  653.     scanf(" %s", password);
  654.  
  655.  
  656.  
  657.  
  658.     qb = fopen("academic.txt", "r");
  659.     if (qb == NULL)
  660.     {
  661.         fprintf(stderr, "\nEOF\n");
  662.         exit(1);
  663.     }
  664.  
  665.     // read file contents till end of file
  666.  
  667.     while (fread(&record, sizeof(struct academicleader), 1, qb)) {
  668.         if (strcmp(emp_name, record.emp_name) == 0 && \
  669.             strcmp(password, record.password) == 0)
  670.         {
  671.             academicleadermenu();
  672.             flag = 1;
  673.             break;
  674.         }
  675.     }
  676.  
  677.     fclose(qb);
  678.  
  679.     if (!flag)
  680.     {
  681.         printf("Invalid Information. Please try again!\n");
  682.         loginAL();
  683.     }
  684.     return 0;
  685.  
  686. }
  687.  
  688. char registrationL()
  689. {
  690.  
  691.     system("cls");
  692.     printf("========================================================================================\n");
  693.     printf("\t\tWELCOME TO LECTURER REGISTRATION!!\n");
  694.     printf("=========================================================================================\n\n");
  695.     date();
  696.     printf("---------------------------------------------------------------------------------------------");
  697.  
  698.     struct lecturer record;
  699.  
  700.     printf("Enter the UserID: ");
  701.     scanf(" %s", record.emp_ID);
  702.  
  703.     printf("\nEnter the username: ");
  704.     scanf(" %s", record.emp_name);
  705.  
  706.     printf("\nEnter the password: ");
  707.     scanf(" %s", record.password);
  708.  
  709.     FILE *qa;
  710.  
  711.     // open file for writing
  712.     qa = fopen("L.txt", "a");
  713.     if (qa == NULL)
  714.     {
  715.         fprintf(stderr, "\nEOF\n");
  716.         exit(1);
  717.     }
  718.  
  719.  
  720.     // write struct to file
  721.     fwrite(&record, sizeof(struct lecturer), 1, qa);
  722.     fclose(qa);
  723.  
  724.     if (fwrite != 0)
  725.         printf("\nRecord Success!!\n");
  726.     else
  727.         printf("ERROR!!\n");
  728.  
  729.  
  730.     return 0;
  731. }
  732.  
  733. int loginL()
  734. {
  735.     //system("cls");
  736.     printf("========================================================================================\n");
  737.     printf("\t\tWELCOME TO LECTURER LOGIN!!\n");
  738.     printf("=========================================================================================\n\n");
  739.     date();
  740.     printf("---------------------------------------------------------------------------------------------");
  741.  
  742.     char emp_name[50];
  743.     char password[50];
  744.     int flag = 0;
  745.  
  746.     FILE *qb;
  747.     struct lecturer record;
  748.  
  749.  
  750.     printf("\nPlease Enter your Username, Password to Proceed\n\n");
  751.     printf("\n\nemp_name: ");
  752.     scanf(" %s", emp_name);
  753.     printf("\nPassword: ");
  754.     scanf(" %s", password);
  755.  
  756.  
  757.     qb = fopen("L.txt", "r");
  758.     if (qb == NULL)
  759.     {
  760.         fprintf(stderr, "\nEOF\n");
  761.         exit(1);
  762.     }
  763.  
  764.     // read file contents till end of file
  765.  
  766.     while (fread(&record, sizeof(struct lecturer), 1, qb)) {
  767.         if (strcmp(emp_name, record.emp_name) == 0 && strcmp(password, record.password) == 0)
  768.         {
  769.             lecturermenu();
  770.             flag = 1;
  771.             break;
  772.         }
  773.     }
  774.  
  775.     fclose(qb);
  776.  
  777.     if (!flag)
  778.     {
  779.         printf("Invalid Information. Please try again!!\n");
  780.         loginL();
  781.     }
  782.     return 0;
  783.  
  784. }
  785.  
  786. void lecturerview()
  787. {
  788.  
  789.     FILE *qb;
  790.     struct lecturer record;
  791.  
  792.  
  793.     // Open user.txt for reading
  794.     qb = fopen("L.txt", "r");
  795.     if (qb == NULL)
  796.     {
  797.         fprintf(stderr, "\nEOF\n");
  798.         exit(1);
  799.     }
  800.  
  801.     // read file contents till end of file
  802.     while (fread(&record, sizeof(struct lecturer), 1, qb))
  803.     {
  804.         //if(strcmp(positionL, person.position) == 0)
  805.         //{
  806.  
  807.         printf("\nUserID = %s \tUsername = %s \tPassword = %s", record.emp_ID,
  808.             record.emp_name, record.password);
  809.         //}
  810.     }
  811.     return;
  812.     fclose(qb);
  813.  
  814. }
  815.  
  816. int deleterecord()
  817. {
  818.     FILE *fp;
  819.     FILE *fp_temp;
  820.     int flag = 0;
  821.     char emp_ID[20];
  822.     struct lecturer record;
  823.  
  824.     printf("Enter user ID: ");
  825.     scanf(" %s", emp_ID);
  826.  
  827.     fp = fopen("L.txt", "r");
  828.     if (!fp) {
  829.         printf("Fail to open file");
  830.         return -1;
  831.     }
  832.     fp_temp = fopen("temp.txt", "w");
  833.     if (!fp_temp) {
  834.         printf("Fail to open temp file.");
  835.         return -1;
  836.     }
  837.  
  838.     while (fread(&record, sizeof(struct lecturer), 1, fp) != NULL) {
  839.         if (strcmp(emp_ID, record.emp_ID) == 0) {
  840.             printf("Request have been found and actions have been taken.\n\n");
  841.             flag = 1;
  842.         }
  843.         else {
  844.             fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
  845.         }
  846.     }
  847.     if (!flag) {
  848.         printf("No record with the requested details is found: %s\n\n", emp_ID);
  849.     }
  850.  
  851.     fclose(fp);
  852.     fclose(fp_temp);
  853.  
  854.     remove("L.txt");
  855.     rename("temp.txt", "L.txt");
  856.  
  857.     return 0;
  858. }
  859.  
  860. int updaterecordL()
  861.  
  862. {
  863.     FILE *fp;
  864.     FILE *fp_temp;
  865.     int flag = 0;
  866.     char emp_ID[20];
  867.  
  868.     struct lecturer record;
  869.  
  870.     printf("Enter user ID: ");
  871.     scanf(" %s", emp_ID);
  872.  
  873.     fp = fopen("L.txt", "a+");
  874.     if (!fp) {
  875.         printf("Fail to open file");
  876.         return -1;
  877.     }
  878.     fp_temp = fopen("temp.txt", "a+");
  879.     if (!fp_temp) {
  880.         printf("Fail to open temp file.");
  881.         return -1;
  882.     }
  883.  
  884.     while (fread(&record, sizeof(struct lecturer), 1, fp) != NULL) {
  885.         if (strcmp(emp_ID, record.emp_ID) == 0) {
  886.             printf("Request have been found and actions have been taken.\n\n");
  887.             flag = 1;
  888.             printf("\nEnter new username: ");
  889.             scanf(" %s", record.emp_name);
  890.             printf("\nEnter new password: ");
  891.             scanf(" %s", record.password);
  892.             fseek(fp_temp, sizeof(struct lecturer), SEEK_CUR);
  893.             fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
  894.  
  895.         }
  896.         else {
  897.             fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
  898.         }
  899.     }
  900.     if (!flag) {
  901.         printf("No record(s) found with the requested name: %s\n\n", emp_ID);
  902.     }
  903.  
  904.     fclose(fp);
  905.     fclose(fp_temp);
  906.  
  907.     remove("L.txt");
  908.     rename("temp.txt", "L.txt");
  909.  
  910.     return 0;
  911. }
  912.  
  913. int searchrecordL()
  914. {
  915.  
  916.     FILE *qb;
  917.     struct lecturer record;
  918.     char emp_ID[20];
  919.  
  920.  
  921.     // Open user.txt for reading
  922.     qb = fopen("L.txt", "r");
  923.     if (qb == NULL)
  924.     {
  925.         fprintf(stderr, "\nEOF\n");
  926.         exit(1);
  927.     }
  928.  
  929.     printf("Enter Lecturer ID: ");
  930.     scanf(" %s", emp_ID);
  931.     // read file contents till end of file
  932.     while (fread(&record, sizeof(struct lecturer), 1, qb))
  933.     {
  934.         if (strcmp(emp_ID, record.emp_ID) == 0)
  935.             //{
  936.  
  937.             printf("\nUserID = %s \tUsername = %s \tPassword = %s", record.emp_ID,
  938.                 record.emp_ID, record.password);
  939.         //}
  940.     }
  941.     return;
  942.     fclose(qb);
  943.  
  944. }
  945.  
  946. int yearlyleaves()
  947. {
  948.  
  949.     system("cls");
  950.     printf("========================================================================================\n");
  951.     printf("\t\tWELCOME TO LEAVE UPDATER!!\n");
  952.     printf("=========================================================================================\n\n");
  953.     date();
  954.     printf("---------------------------------------------------------------------------------------------");
  955.  
  956.     struct yearlyleaves record;
  957.  
  958.     printf("Enter Number of Yearly Leaves: ");
  959.     scanf(" %d", &record.days);
  960.  
  961.  
  962.  
  963.     printf("Yearly leaves is now set to %d days \n", record.days);
  964.  
  965.  
  966.     FILE *qa;
  967.  
  968.     // open file for writing
  969.     qa = fopen("yearlyleaves.txt", "w");
  970.     if (qa == NULL)
  971.     {
  972.         fprintf(stderr, "\nEOF\n");
  973.         exit(1);
  974.     }
  975.  
  976.  
  977.     // write struct to file
  978.     fwrite(&record, sizeof(struct yearlyleaves), 1, qa);
  979.     fclose(qa);
  980.  
  981.     if (fwrite != 0)
  982.         printf("\nRecord Success!!\n");
  983.     else
  984.         printf("ERROR!!\n");
  985.  
  986.  
  987.     return 0;
  988.  
  989.  
  990. }
  991.  
  992. int updateholidays()
  993. {
  994.  
  995.     system("cls");
  996.     printf("========================================================================================\n");
  997.     printf("\t\tWELCOME TO PUBLIC HOLIDAYS UPDATER!!\n");
  998.     printf("=========================================================================================\n\n");
  999.     date();
  1000.     printf("---------------------------------------------------------------------------------------------");
  1001.  
  1002.     struct holidays record;
  1003.  
  1004. date:
  1005.     printf("Enter date (DD/MM/YYYY format): ");
  1006.     fflush(stdin);
  1007.     scanf(" %d/%d/%d", &record.dd, &record.mm, &record.yy);
  1008.     if (record.yy >= 1900 && record.yy <= 9999)
  1009.     {
  1010.         //check month
  1011.         if (record.mm >= 1 && record.mm <= 12)
  1012.         {
  1013.             //check days
  1014.             if ((record.dd >= 1 && record.dd <= 31) && (record.mm == 1 || record.mm == 3 || record.mm == 5 || record.mm == 7 || record.mm == 8 || record.mm == 10 || record.mm == 12)) {
  1015.                 printf("Valid Date.\n");
  1016.             }
  1017.             else if ((record.dd >= 1 && record.dd <= 30) && (record.mm == 4 || record.mm == 6 || record.mm == 9 || record.mm == 11)) {
  1018.                 printf("Valid Date.\n");
  1019.             }
  1020.             else if ((record.dd >= 1 && record.dd <= 28) && (record.mm == 2)) {
  1021.                 printf("Valid Date.\n");
  1022.             }
  1023.             else if (record.dd == 29 && record.mm == 2 && (record.yy % 400 == 0 || (record.yy % 4 == 0 && record.yy % 100 != 0))) {
  1024.                 printf("Valid Date.\n");
  1025.             }
  1026.             else {
  1027.                 printf("Invalid Date.\n");
  1028.                 goto date;
  1029.             }
  1030.         }
  1031.         else
  1032.         {
  1033.             printf("Invalid Date.\n");
  1034.             goto date;
  1035.         }
  1036.     }
  1037.     else
  1038.     {
  1039.         printf("Invalid Date.\n");
  1040.         goto date;
  1041.     }
  1042.  
  1043.     printf("Enter the Description of Holiday: ");
  1044.     scanf(" %[^\n]%*c", record.description);
  1045.  
  1046.  
  1047.  
  1048.     printf("Public Holiday described as %s on date %d/%d/%d added\n", record.description, record.dd, record.mm, record.yy);
  1049.  
  1050.  
  1051.     FILE *qa;
  1052.  
  1053.     // open file for writing
  1054.     qa = fopen("holiday.txt", "a");
  1055.     if (qa == NULL)
  1056.     {
  1057.         fprintf(stderr, "\nEOF\n");
  1058.         exit(1);
  1059.     }
  1060.  
  1061.  
  1062.     // write struct to file
  1063.     fwrite(&record, sizeof(struct holidays), 1, qa);
  1064.     fclose(qa);
  1065.  
  1066.     if (fwrite != 0)
  1067.         printf("\nRecord Success!!\n");
  1068.     else
  1069.         printf("ERROR!!\n");
  1070.  
  1071.  
  1072.     return 0;
  1073.  
  1074. }
  1075.  
  1076.  
  1077. int universitypolicies()
  1078. {
  1079.     system("cls");
  1080.     printf("========================================================================================\n");
  1081.     printf("\t\tWELCOME TO ABC POLICIES UPDATER!!\n");
  1082.     printf("=========================================================================================\n\n");
  1083.     date();
  1084.     printf("---------------------------------------------------------------------------------------------");
  1085.  
  1086.     struct policies record;
  1087.  
  1088.     FILE *qa;
  1089.  
  1090.     // open file for writing
  1091.     qa = fopen("policies.txt", "a+");
  1092.     if (qa == NULL)
  1093.     {
  1094.         fprintf(stderr, "\nEOF\n");
  1095.         exit(1);
  1096.     }
  1097.  
  1098.     char number[5];
  1099.  
  1100. number:
  1101.     printf("Input Number of Policy: ");
  1102.     scanf(" %s", number);
  1103.     while (fread(&record, sizeof(struct policies), 1, qa)) {
  1104.         if (strcmp(record.count, number) == 0) {
  1105.             printf("\nNumber already exist! Insert another number.\n");
  1106.             goto number;
  1107.         }
  1108.     }
  1109.     strcpy(record.count, number);
  1110.     printf("\nInsert Policy: ");
  1111.     scanf(" %[^\n]%*c", record.policies);
  1112.  
  1113.     printf("New Policy added \n%s. %s\n", record.count, record.policies);
  1114.  
  1115.     // write struct to file
  1116.     fwrite(&record, sizeof(struct policies), 1, qa);
  1117.     fclose(qa);
  1118.  
  1119.     if (fwrite != 0)
  1120.         printf("\nRecord Success!!\n");
  1121.     else
  1122.         printf("ERROR!!\n");
  1123.  
  1124.  
  1125.     return 0;
  1126.  
  1127. }
  1128.  
  1129. int updatepolicies()
  1130.  
  1131. {
  1132.     FILE *fp;
  1133.     FILE *fp_temp;
  1134.     int flag = 0;
  1135.     int number[5];
  1136.  
  1137.     struct policies record;
  1138.  
  1139.     printf("Enter Policy Number: ");
  1140.     scanf(" %s", number);
  1141.  
  1142.     fp = fopen("policies.txt", "r");
  1143.     if (!fp) {
  1144.         printf("Unable to open file");
  1145.         return -1;
  1146.     }
  1147.     fp_temp = fopen("temp.txt", "w");
  1148.     if (!fp_temp) {
  1149.         printf("Unable to open file temp file.");
  1150.         return -1;
  1151.     }
  1152.  
  1153.     while (fread(&record, sizeof(struct policies), 1, fp) != NULL) {
  1154.         if (strcmp(number, record.count) == 0) {
  1155.             printf("A record with requested name found and deleted.\n\n");
  1156.             flag = 1;
  1157.             printf("\nEnter new Policy: ");
  1158.             scanf(" %s", record.policies);
  1159.             fseek(fp_temp, sizeof(struct policies), SEEK_CUR);
  1160.             fwrite(&record, sizeof(struct policies), 1, fp_temp);
  1161.             printf("%s %s", record.count, record.policies);
  1162.  
  1163.         }
  1164.         else {
  1165.             fwrite(&record, sizeof(struct policies), 1, fp_temp);
  1166.         }
  1167.     }
  1168.     if (!flag) {
  1169.         printf("No record(s) found with the requested name: %s\n\n", number);
  1170.     }
  1171.  
  1172.     fclose(fp);
  1173.     fclose(fp_temp);
  1174.  
  1175.     remove("policies.txt");
  1176.     rename("temp.txt", "policies.txt");
  1177.  
  1178.     return 0;
  1179. }
  1180.  
  1181.  
  1182. int viewholidays()
  1183. {
  1184.     FILE *qb;
  1185.     struct holidays record;
  1186.  
  1187.  
  1188.     // Open user.txt for reading
  1189.     qb = fopen("holiday.txt", "r");
  1190.     if (qb == NULL)
  1191.     {
  1192.         fprintf(stderr, "\nError opening file\n");
  1193.         exit(1);
  1194.     }
  1195.  
  1196.     // read file contents till end of file
  1197.     while (fread(&record, sizeof(struct holidays), 1, qb))
  1198.     {
  1199.         //if(strcmp(positionL, person.position) == 0)
  1200.         //{
  1201.  
  1202.         printf("Holiday due to %s on date %d/%d/%d\n", record.description, record.dd,
  1203.             record.mm, record.yy);
  1204.         //}
  1205.     }
  1206.     return;
  1207.     fclose(qb);
  1208. }
  1209.  
  1210. int viewFAQ()
  1211.  
  1212. {
  1213.     FILE *qb;
  1214.     struct policies record;
  1215.  
  1216.  
  1217.     // Open user.txt for reading
  1218.     qb = fopen("policies.txt", "r");
  1219.     if (qb == NULL)
  1220.     {
  1221.         fprintf(stderr, "\nEOF\n");
  1222.         exit(1);
  1223.     }
  1224.  
  1225.     // read file contents till end of file
  1226.     printf("FAQ About Lecturer Leave Policies are\n\n");
  1227.     while (fread(&record, sizeof(struct policies), 1, qb))
  1228.     {
  1229.  
  1230.         printf("%s. %s\n", record.count, record.policies);
  1231.  
  1232.     }
  1233.     return;
  1234.     fclose(qb);
  1235. }
  1236.  
  1237. int leaveapplication()
  1238.  
  1239. {
  1240.  
  1241.     system("cls");
  1242.     printf("========================================================================================\n");
  1243.     printf("\t\tWELCOME TO ABC LEAVE APPLICATION!!\n");
  1244.     printf("=========================================================================================\n\n");
  1245.     date();
  1246.     printf("---------------------------------------------------------------------------------------------");
  1247.  
  1248.     struct leaveapplication record;
  1249.  
  1250.     printf("Enter the userID: ");
  1251.     scanf(" %s", record.emp_ID);
  1252.  
  1253.     printf("\nEnter your First Name: ");
  1254.     scanf(" %s", record.emp_name);
  1255.  
  1256.     printf("\nEnter your Reason: ");
  1257.     scanf(" %s", record.subject);
  1258.  
  1259.     char status[20] = "Pending";
  1260.  
  1261.     strcpy(record.status, status);
  1262. date:
  1263.     printf("Enter the date of leave(DD/MM/YYYY format): ");
  1264.     fflush(stdin);
  1265.     scanf(" %d/%d/%d", &record.dd, &record.mm, &record.yy);
  1266.     if (record.yy >= 1900 && record.yy <= 9999)
  1267.     {
  1268.         //check month
  1269.         if (record.mm >= 1 && record.mm <= 12)
  1270.         {
  1271.             //check days
  1272.             if ((record.dd >= 1 && record.dd <= 31) && (record.mm == 1 || record.mm == 3 || record.mm == 5 || record.mm == 7 || record.mm == 8 || record.mm == 10 || record.mm == 12)) {
  1273.                 printf("Valid Date.\n");
  1274.             }
  1275.             else if ((record.dd >= 1 && record.dd <= 30) && (record.mm == 4 || record.mm == 6 || record.mm == 9 || record.mm == 11)) {
  1276.                 printf("Valid Date.\n");
  1277.             }
  1278.             else if ((record.dd >= 1 && record.dd <= 28) && (record.mm == 2)) {
  1279.                 printf("Valid Date.\n");
  1280.             }
  1281.             else if (record.dd == 29 && record.mm == 2 && (record.yy % 400 == 0 || (record.yy % 4 == 0 && record.yy % 100 != 0))) {
  1282.                 printf("Valid Date.\n");
  1283.             }
  1284.             else {
  1285.                 printf("Invalid Date.\n");
  1286.                 goto date;
  1287.             }
  1288.         }
  1289.         else
  1290.         {
  1291.             printf("Invalid Date.\n");
  1292.             goto date;
  1293.         }
  1294.     }
  1295.     else
  1296.     {
  1297.         printf("Invalid Date.\n");
  1298.         goto date;
  1299.     }
  1300.  
  1301.     FILE *qa;
  1302.  
  1303.     // open file for writing
  1304.     qa = fopen("leave.txt", "a");
  1305.     if (qa == NULL)
  1306.     {
  1307.         fprintf(stderr, "\nEOF\n");
  1308.         exit(1);
  1309.     }
  1310.  
  1311.  
  1312.     // write struct to file
  1313.     fwrite(&record, sizeof(struct leaveapplication), 1, qa);
  1314.     fclose(qa);
  1315.  
  1316.     if (fwrite != 0)
  1317.         printf("\nRecord Success!!\n");
  1318.     else
  1319.         printf("ERROR!!\n");
  1320.  
  1321.  
  1322.     return 0;
  1323.  
  1324. }
  1325.  
  1326.  
  1327. int statusview()
  1328.  
  1329. {
  1330.     FILE *qb;
  1331.     struct leaveapplication record;
  1332.     char userID[5];
  1333.  
  1334.  
  1335.     // Open user.txt for reading
  1336.     qb = fopen("leave.txt", "r");
  1337.     if (qb == NULL)
  1338.     {
  1339.         fprintf(stderr, "\nEOF\n");
  1340.         exit(1);
  1341.     }
  1342.  
  1343.     printf("Enter Lecturer ID: ");
  1344.     scanf(" %s", userID);
  1345.     // read file contents till end of file
  1346.     while (fread(&record, sizeof(struct leaveapplication), 1, qb))
  1347.     {
  1348.         if (strcmp(userID, record.emp_ID) == 0)
  1349.             //{
  1350.  
  1351.             printf("\nUserID = %s \tfirstname = %s \tlastname = %s \tStatus =%s \tDate = %d/%d/%d", record.emp_ID,
  1352.                 record.emp_name, record.status, record.dd, record.mm, record.yy);
  1353.         //}
  1354.     }
  1355.     return;
  1356.     fclose(qb);
  1357. }
  1358.  
  1359. int changestatus()
  1360.  
  1361. {
  1362.     FILE *fp;
  1363.     FILE *fp_temp;
  1364.     int flag = 0;
  1365.     char userID[5];
  1366.  
  1367.     struct leaveapplication record;
  1368.  
  1369.     printf("Enter user ID: ");
  1370.     scanf(" %s", userID);
  1371.  
  1372.     fp = fopen("leave.txt", "a+");
  1373.     if (!fp) {
  1374.         printf("Fail to open file");
  1375.         return -1;
  1376.     }
  1377.     fp_temp = fopen("temp.txt", "a+");
  1378.     if (!fp_temp) {
  1379.         printf("Fail to open temp file.");
  1380.         return -1;
  1381.     }
  1382.  
  1383.     while (fread(&record, sizeof(struct leaveapplication), 1, fp) != NULL) {
  1384.         if (strcmp(userID, record.emp_ID) == 0) {
  1385.             printf("A record with requested name found and deleted.\n\n");
  1386.             flag = 1;
  1387.             printf("\nEnter new Status: ");
  1388.             scanf(" %s", record.status);;
  1389.             fseek(fp_temp, sizeof(struct leaveapplication), SEEK_CUR);
  1390.             fwrite(&record, sizeof(struct leaveapplication), 1, fp_temp);
  1391.  
  1392.         }
  1393.         else {
  1394.             fwrite(&record, sizeof(struct leaveapplication), 1, fp_temp);
  1395.         }
  1396.     }
  1397.     if (!flag) {
  1398.         printf("No record(s) found with the requested name: %s\n\n", userID);
  1399.     }
  1400.  
  1401.     fclose(fp);
  1402.     fclose(fp_temp);
  1403.  
  1404.     remove("leave.txt");
  1405.     rename("temp.txt", "leave.txt");
  1406.  
  1407.     return 0;
  1408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement