Guest User

Untitled

a guest
Jan 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. //Project C Language
  2. //Library System
  3. //CreateBy
  4. //1.Kriangkrai Aroontheerapoj Sec.3 ID:5488026
  5. //2.
  6. //3.
  7.  
  8. //======================= Declaration ===================================//
  9. #include<stdio.h>
  10. #include<string.h>
  11. #include<stdlib.h>
  12. #include<time.h>
  13.  
  14. void chkUsrOrStaff(int);
  15. void chkMember(int);
  16. void wantToDo(int);
  17. int registMember(char);
  18. int addBook(char);
  19. int removeBook(char);
  20. int OverDue(char);
  21. int borrowBook();
  22. int returnBook();
  23.  
  24. struct usernamepassword
  25. {
  26. char username[8+1];
  27. char password[8+1];
  28. };
  29. struct book
  30. {
  31. char bookID[8+1];
  32. char bookName[500+1];
  33. };
  34.  
  35. struct usernamepassword user[100];
  36. struct usernamepassword chkuser[1];
  37. struct book book[100];
  38. struct book chkbook[1];
  39. int i=0,count=0;
  40. FILE *fid;
  41. FILE *fie;
  42. //======================= Main Function ===================================//
  43. int main()
  44. {
  45. int usrOrStaff;
  46. printf("\n\n====== Welcome to Library System ======\n\n");
  47. printf("Who are You?\n");
  48. printf("1. User\n");
  49. printf("2. Staff\n\n");
  50. printf("Enter 1 or 2: ");
  51. scanf("%d",&usrOrStaff);
  52. system("cls");
  53. chkUsrOrStaff(usrOrStaff);
  54. getch();
  55. return 0;
  56. }
  57. //======================= check User Or Staff ===========================//
  58. void chkUsrOrStaff(int usrOrStaff)
  59. { int memOrNot;
  60. if(usrOrStaff==1)
  61. {
  62. printf("\n\nYou are User");
  63. printf("\n\n========================================\n\n");
  64. printf("Are you Member?\n");
  65. printf("1. Yes\n");
  66. printf("2. No\n\n");
  67. printf("Enter 1 or 2: ");
  68. scanf("%d",&memOrNot);
  69. system("cls");
  70. chkMember(memOrNot);
  71. }
  72. else if(usrOrStaff==2)
  73. {
  74. printf("You are Staff");
  75. }
  76. }
  77. //========================== check Member ==============================//
  78. void chkMember(int memOrNot)
  79. { int chkWant,chkUsr,chkPsw,chkRegis,count;
  80. struct usernamepassword regUser[1];
  81.  
  82. if(memOrNot==1)
  83. {
  84. printf("\n\nYou are member");
  85. printf("\n\n====== Plese enter username and password ====== \n\n");
  86.  
  87. fid = fopen("user.txt","r");
  88. if(!(fid==NULL))
  89. {
  90. while(!feof(fid))
  91. {
  92. fscanf(fid,"%s %s \n",user[i].username,user[i].password);
  93. i++;
  94. count++;
  95. }
  96. }
  97. do
  98. {
  99. printf("\nEnter username: ");
  100. scanf("%s",&chkuser[0].username);
  101. printf("Enter password: ");
  102. scanf("%s",&chkuser[0].password);
  103. for(i=0;i<count;i++)
  104. {
  105. chkUsr=strcmp(chkuser[0].username,user[i].username);
  106. chkPsw=strcmp(chkuser[0].password,user[i].password);
  107. if(chkUsr==0 && chkPsw==0)
  108. {
  109. break;
  110. }
  111. }
  112. }while(chkUsr!=0 || chkPsw!=0);
  113. fclose(fid);
  114. printf("Password Correct");
  115. system("cls");
  116. printf("\n\n========== Welcome ==========\n\n");
  117. printf("---- What do you want to do? ----\n");
  118. printf("1.Borrow Book(s)");
  119. printf("\n2.Return Book(s)");
  120. printf("\n\nEnter 1 or 2: ");
  121. scanf("%d",&chkWant);
  122. wantToDo(chkWant);
  123. }
  124. else if(memOrNot==2)
  125. {
  126. printf("You are non-member\n");
  127. printf("\n==========================\n");
  128. printf("What do you want to do\n\n");
  129. printf("1. Register\n");
  130. printf("2. Exit\n\n");
  131. printf("Enter 1 or 2: ");
  132. scanf("%d",&chkRegis);
  133. if(chkRegis==1)
  134. {
  135. system("cls");
  136. fid = fopen("user.txt","a+t");
  137. printf("======= Register System =======\n\n");
  138. printf("Enter username: ");
  139. scanf("%s",regUser[0].username);
  140. printf("Enter password: ");
  141. scanf("%s",regUser[0].password);
  142. fprintf(fid,"\n%s \t %s",regUser[0].username,regUser[0].password);
  143. printf("\nRegister Successful.");
  144. printf("\n\nNow you can login and borrow/return book(s).");
  145. fclose(fid);
  146. getch();
  147. system("cls");
  148. memOrNot=1;
  149. chkMember(memOrNot);
  150. }
  151. else if(chkRegis==2)
  152. {
  153. exit(1);
  154. }
  155. }
  156. }
  157. //========================== Check What User Want to do======================//
  158. void wantToDo(int chkWant)
  159. {
  160. if(chkWant==1)
  161. {
  162. borrowBook();
  163. }
  164. else if(chkWant==2)
  165. {
  166. }
  167. }
  168. //========================== Borrow Books system ============================//
  169. int borrowBook(int qty)
  170. {
  171. int qtyBorrow,chkBookID,j,chk;
  172. char borrowBookID[8];
  173. system("cls");
  174. printf("\n\n====== Borrow Book(s) System ======\n\n");
  175. do
  176. {
  177. printf("How many Book(s) that you want to Borrow(Maximum 5): ");
  178. scanf("%d",&qtyBorrow);
  179. }while(qtyBorrow>5);
  180.  
  181. fie = fopen("book.txt","r");
  182. if(!(fie==NULL))
  183. {
  184. while(!feof(fie))
  185. {
  186. fscanf(fie,"%s\n",book[i].bookID);
  187. fgets(book[i].bookName,51,fie);
  188. i++;
  189. count++;
  190. }
  191. }
  192. for(i=0;i<count;i++)
  193. {
  194. printf("%s\t%s",book[i].bookID,book[i].bookName);
  195. }
  196. for(i=0;i<qtyBorrow;i++)
  197. {
  198. printf("\n\nEnter %d book ID: ",i+1);
  199. scanf("%s",&borrowBookID[i]);
  200. }
  201. printf("\nYou borrow:\n");
  202. for(i=0;i<qtyBorrow;i++)
  203. { for(j=0;j<count;j++)
  204. {
  205. if(strcmp(&borrowBookID[i],book[j].bookID)==0)
  206. {
  207. chk=j;
  208. break;
  209. }
  210. }
  211. printf("%s\t%s",book[chk].bookID,book[chk].bookName);
  212. }
  213. }
Add Comment
Please, Sign In to add comment