Advertisement
Elzerk

library system.c

Dec 9th, 2019
1,625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. //global variables
  5. int role,i = 0;
  6. char full_name[50],student_no[50],emp_no[50];
  7. int rb1=0,rb2=0,rb3=0,rb4=0,rb5=0;//reserve books
  8. int bb1=0,bb2=0,bb3=0,bb4=0,bb5=0;//borrow books
  9. char returnBooks[100];
  10.  
  11. void menu();
  12. void borrow();
  13. void reserve();
  14. void review();
  15. int main(){
  16.     printf("LIBRAY SYSTEM MANAGEMENT ...\n");
  17.     printf("Are you ? \n[1] student \n[2] employer\n ~");
  18.     scanf("%d",&role);
  19.     fflush(stdin);
  20.     if(role == 1){
  21.         printf("Enter your name ~ ");
  22.         gets(full_name);
  23.         printf("Enter your student number ~ ");
  24.         gets(student_no);
  25.     }else if(role == 2){
  26.         printf("Enter you id number ~");
  27.         gets(emp_no);
  28.     }else {
  29.         getch();
  30.         system("cls");
  31.         return 0;
  32.     }
  33.     menu();
  34.     return 0;
  35. }
  36. void reserve(){
  37.     int choice;
  38.     while(1){
  39.          system("cls");
  40.         printf("AVAILABLE BOOKS\n--------------------\n");
  41.         printf("Book#               Name\n");
  42.         if(rb1 != 1) printf("1                mathematics\n");
  43.         if(rb2 != 2) printf("2                Arts\n");
  44.         if(rb3 != 3) printf("3                Science\n");
  45.         if(rb4 != 4) printf("4                English\n");
  46.         if(rb5 != 5) printf("5                MAPEH\n");
  47.         if(rb1 == 1&&rb2 == 2&&rb3 == 3&&rb4 == 4&&rb5 == 5){
  48.              printf("NO AVAILABLE BOOKS TO RESERVE!");
  49.              getch();
  50.              menu();
  51.         }
  52.         printf("Enter the Book# you want to reserve, enter [9] to back to menu~ ");
  53.         scanf("%d",&choice);
  54.         fflush(stdin);
  55.         if(choice == 9)menu();
  56.         if(choice == 1) {
  57.             rb1 = 1;
  58.             continue;  
  59.         }
  60.         if(choice == 2){
  61.             rb2 = 2;
  62.             continue;  
  63.         }
  64.         if(choice == 3){
  65.             rb3 = 3;
  66.             continue;
  67.         }
  68.         if(choice == 4){
  69.             rb4 = 4;
  70.             continue;
  71.         }
  72.         if(choice == 5){
  73.              rb5 = 5;
  74.              continue;
  75.         }
  76.         else printf("not available !\n");
  77.     }
  78. }
  79. void review(){
  80.     system("cls");
  81.     if(role == 1){
  82.         printf("Type : Student\nName : %s\nStudent # : %s\n\n",full_name,student_no);
  83.     }else {
  84.         printf("Type : Employer\nId# : %s\n\n",emp_no);
  85.     }
  86.      printf("Reserved books \n");
  87.         if(rb1 != 0){
  88.             printf("-book 1 mathematics\n");
  89.         }
  90.         if(rb2 != 0){
  91.             printf("-book 2 Arts\n");
  92.         }
  93.         if(rb3 != 0){
  94.             printf("-book 3 Science\n");
  95.         }
  96.         if(rb4 != 0){
  97.             printf("-book 4 English\n");
  98.         }
  99.         if(rb5 != 0){
  100.             printf("-book 5 Mapeh\n");
  101.         }
  102.         printf("\nBorrowed  books \n");
  103.         if(bb1 != 0){
  104.             printf("-book 1 ethics\n");
  105.         }
  106.         if(bb2 != 0){
  107.             printf("-book 2 Rizal\n");
  108.         }
  109.         if(bb3 != 0){
  110.             printf("-book 3 Programming\n");
  111.         }
  112.         if(bb4 != 0){
  113.             printf("-book 4 Arts\n");
  114.         }
  115.         if(bb5 != 0){
  116.             printf("-book 5 Computing\n");
  117.         }
  118.         printf("\nReturned Books \n%s",returnBooks);
  119.     getch();
  120.     menu();
  121. }
  122. void borrow(){
  123.      int choice;
  124.     while(1){
  125.          system("cls");
  126.         printf("AVAILABLE BOOKS\n--------------------\n");
  127.         printf("Book#               Name\n");
  128.         if(bb1 != 1) printf("1                Ethics\n");
  129.         if(bb2 != 2) printf("2                Rizal\n");
  130.         if(bb3 != 3) printf("3                Programming\n");
  131.         if(bb4 != 4) printf("4                Arts\n");
  132.         if(bb5 != 5) printf("5                Computing\n");
  133.         if(bb1 == 1&&bb2 == 2&&bb3 == 3&&bb4 == 4&&bb5 == 5){
  134.              printf("NO AVAILABLE BOOKS TO BORROW!");
  135.              getch();
  136.              menu();
  137.         }
  138.         printf("Enter the Book# you want to borrow, enter [9] to back to menu~ ");
  139.         scanf("%d",&choice);
  140.         fflush(stdin);
  141.         if(choice == 9)menu();
  142.         if(choice == 1) {
  143.             bb1 = 1;
  144.             continue;
  145.         }
  146.         if(choice == 2){
  147.             bb2 = 2;
  148.             continue;
  149.         }
  150.         if(choice == 3){
  151.             bb3 = 3;
  152.             continue;
  153.         }
  154.         if(choice == 4){
  155.             bb4 = 4;
  156.             continue;
  157.         }
  158.         if(choice == 5){
  159.             bb5 = 5;
  160.             continue;
  161.         }
  162.         else printf("not available !\n");
  163.         getch();
  164.     }
  165.  
  166. }
  167.  
  168. void rBooks(){
  169.     int choice;
  170.     while(1){
  171.          system("cls");
  172.         printf("RETURN BOOKS\n--------------------\n");
  173.         printf("Book#               Name\n");
  174.         if(bb1 == 1) printf("1                Ethics\n");
  175.         if(bb2 == 2) printf("2                Rizal\n");
  176.         if(bb3 == 3) printf("3                Programming\n");
  177.         if(bb4 == 4) printf("4                Arts\n");
  178.         if(bb5 == 5) printf("5                Computing\n");
  179.         if(bb1 != 1&&bb2 != 2&&bb3 != 3&&bb4 != 4&&bb5 != 5){
  180.              printf("NO AVAILABLE BOOKS TO RETURN!");
  181.              getch();
  182.              menu();
  183.         }
  184.         printf("Enter the Book# you want to Return, enter [9] to back to menu~ ");
  185.         scanf("%d",&choice);
  186.         fflush(stdin);
  187.         if(choice == 9)menu();
  188.         if(choice == 1) bb1 = 0;
  189.         if(choice == 2) bb2 = 0;
  190.         if(choice == 3) bb3 = 0;
  191.         if(choice == 4) bb4 = 0;
  192.         if(choice == 5) bb5 = 0;
  193.         else printf("not available !\n");
  194.         getch();
  195.     }
  196. }
  197. void menu(){
  198.     int choose;
  199.     char ch;
  200.     system("cls");
  201.     printf("-----MENU----\n");
  202.  
  203.     printf("Options ~\n[1] reservation book \n[2] borrow book\n[3] return book \n[4] Review Books\n[5] Exit\n~ ");
  204.     scanf("%d",&choose);
  205.     fflush(stdin);
  206.     if(choose == 1){
  207.         reserve();
  208.     }if(choose == 2){
  209.         borrow();
  210.     }else if(choose == 3){
  211.         rBooks();
  212.     }else if(choose == 4)review();
  213.     else if(choose == 5) {
  214.             printf("end session ! Thank you for using library system!");
  215.         getch();
  216.         system("cls");
  217.         exit(0);
  218.     }
  219.  
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement