Advertisement
Guest User

Untitled

a guest
Jan 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. /*
  2. *Progamer's Name: Dillon Bong Zi Hang
  3. *Program Description: Library Management System Login Menu
  4. *Last Updated: 24 - January - 2016
  5. */
  6.  
  7. // Header File
  8. #include"LMS_Header.h"
  9.  
  10. /* Library Management System Login Menu */
  11.  
  12. int main(void)
  13. {
  14. // Label A for invalid input in Login
  15. A:
  16.  
  17. // Get username and password and ignore whitespace
  18. printf("***********************************************\n");
  19. printf("* Library Management System *\n");
  20. printf("***********************************************\n\n");
  21. printf("Username: ");
  22. scanf("%s", &u);
  23. fflush(stdin);
  24. printf("\nPassword: ");
  25. scanf("%s", &p);
  26. fflush(stdin);
  27.  
  28. // Entered username and password is equal to Admin
  29. if ((stricmp(username, u)) == 0 && (strcmp(password, p)) == 0)
  30. {
  31. // Login success from login menu. Go to Main Menu
  32. {
  33. printf("\nLogin Successful\n\n");
  34. system("pause");
  35. system("cls");
  36. Main_Menu();
  37. }
  38. }
  39. else
  40. {
  41. // Login failed from login menu. Re-enter username and password
  42. printf("\nLogin Failed\n\n");
  43. system("pause");
  44. system("cls");
  45. goto A;
  46. }
  47. system("pause>nul");
  48. return 0;
  49. getch();
  50. }
  51.  
  52. /* Library Management System Main Menu */
  53. Main_Menu(void)
  54. {
  55. printf("***********************************************\n");
  56. printf("* Main Menu *\n");
  57. printf("***********************************************\n\n");
  58. printf("1. Add New Book\n");
  59. printf("2. Modify Book Details\n");
  60. printf("3. Remove Book\n");
  61. printf("4. View Book List\n");
  62. printf("5. Book Check In\n");
  63. printf("6. Book Check Out\n");
  64. printf("7. Search Menu\n");
  65. printf("8. View Logs\n");
  66. printf("9. Exit\n\n");
  67. printf("Please select an option: ");
  68. {
  69. // Gets user's option
  70. gets(main_menu_option);
  71. // if user confirmation's string length is equal to 1
  72. if (strlen(main_menu_option) == 1)
  73. {
  74. switch (main_menu_option[0])
  75. {
  76. // Goto Add New Book Menu
  77. case '1':
  78. fflush(stdin);
  79. system("cls");
  80. Add_New_Book();
  81. break;
  82. // Goto Modify Book Details
  83. case '2':
  84. fflush(stdin);
  85. system("cls");
  86. Modify_Book_Details();
  87. break;
  88. case '3':
  89. printf("");
  90. break;
  91. case '4':
  92. printf("");
  93. break;
  94. case '5':
  95. printf("");
  96. break;
  97. case '6':
  98. printf("");
  99. break;
  100. case '7':
  101. printf("");
  102. break;
  103. case '8':
  104. printf("");
  105. break;
  106. case '9':
  107. // Terminating the Program
  108. printf("\nProgram will now terminate. Press any key to continue");
  109. system("pause>nul");
  110. exit(0);
  111. break;
  112. default:
  113. // Invalid Input from the user
  114. printf("\nInvalid input please re-enter an option");
  115. system("pause>nul");
  116. system("cls");
  117. Main_Menu();
  118. break;
  119. }
  120. }
  121. else
  122. {
  123. printf("\nInvalid input please re-enter an option");
  124. system("pause>nul");
  125. system("cls");
  126. Main_Menu();
  127. fflush(stdin);
  128. }
  129.  
  130. }
  131. }
  132.  
  133.  
  134. /* Add New Book Menu */
  135. void Add_New_Book(void)
  136. {
  137. struct Books_Data t;
  138. {
  139. // Open Book Data Text File in append or create binary mode
  140. file_pointer = fopen("Book Data.dat", "ab");
  141. // If file is unable to open, then display error
  142. if (file_pointer == NULL)
  143. {
  144. printf("\nFile cannot be opened.");
  145. system("pause>nul");
  146. system("cls");
  147. Main_Menu();
  148. }
  149. else
  150. {
  151. printf("***********************************************\n");
  152. printf("* Add New Book *\n");
  153. printf("***********************************************\n\n");
  154.  
  155. // Accept Book ID as input
  156. printf("1. Book ID: ");
  157. gets(t.Book_ID);
  158. fflush(stdin);
  159.  
  160. // Accept Book Title as input
  161. printf("\n2. Book Title: ");
  162. gets(t.Book_Title);
  163. fflush(stdin);
  164.  
  165. // Accept Book Edition as input
  166. printf("\n3. Book Edition: ");
  167. gets(t.Book_Edition);
  168. fflush(stdin);
  169.  
  170. // Accept Year of Publication as input
  171. printf("\n4. Year of Publication: ");
  172. gets(t.Year_of_Publication);
  173. fflush(stdin);
  174.  
  175. // Accept Shelf Location as input
  176. printf("\n5. Shelf Location: ");
  177. gets(t.Shelf_Location);
  178. fflush(stdin);
  179.  
  180. // Accept Price as input
  181. printf("\n5. Price(RM): ");
  182. gets(t.Price);
  183. fflush(stdin);
  184.  
  185. // Do loop to confirm data
  186. printf("\nConfirm (y/n)? Type esc to return to Main Menu: ");
  187. do
  188. {
  189. // Set num equals to 0
  190. num = 0;
  191. gets(add_new_book_confirm);
  192. fflush(stdin);
  193. // Compare user input to escape
  194. if (stricmp(add_new_book_confirm, escape) != 0)
  195. {
  196. // if user confirmation's string length is equal to 1
  197. if (strlen(add_new_book_confirm) == 1)
  198. {
  199. switch (add_new_book_confirm[0])
  200. {
  201. // Save all data into file
  202. case 'y':
  203. {
  204. fwrite(&t, sizeof(t), 1, file_pointer);
  205. fclose(file_pointer);
  206. fflush(stdin);
  207. num1 = 0;
  208. printf("\nRecord Successfully Added. Add new book (y/n): ");
  209. // Do loop to get add new book input
  210. do
  211. {
  212. gets(add_more_book_confirm);
  213. fflush(stdin);
  214. if (strlen(add_more_book_confirm) == 1)
  215. {
  216. switch (add_more_book_confirm[0])
  217. {
  218. case 'y':
  219. system("cls");
  220. Add_New_Book();
  221. break;
  222. case 'n':
  223. system("cls");
  224. Main_Menu();
  225. break;
  226. default:
  227. fflush(stdin);
  228. printf("\nInvalid input. Please Re-Enter Confirmation to Add New Book: ");
  229. num1++;
  230. }
  231. }
  232. else
  233. {
  234. fflush(stdin);
  235. printf("\nInvalid input. Please Re-Enter Confirmation to Add New Book: ");
  236. num1++;
  237. }
  238. } while (num1 == 1);
  239. break;
  240. }
  241. // Return to Add New Book Menu
  242. case 'n':
  243. {
  244. fflush(stdin);
  245. fclose(file_pointer);
  246. system("cls");
  247. Add_New_Book();
  248. break;
  249. }
  250. // Invalid Input. Re-enter user confirmation and increment 1 to num
  251. default:
  252. {
  253. fflush(stdin);
  254. printf("\nInvalid input. Please Re-Enter Confirmation: ");
  255. num++;
  256. break;
  257. }
  258. }
  259. }
  260. else
  261. {
  262. // Invalid Input. Re-enter user confirmation and increment 1 to num
  263. printf("\nInvalid input. Please Re-Enter Confirmation: ");
  264. num++;
  265. }
  266.  
  267. }
  268. // User input equals to esc then return to main menu
  269. else if (stricmp(add_new_book_confirm, escape) == 0)
  270. {
  271. fclose(file_pointer);
  272. printf("\nThe program will now return to Main Menu");
  273. system("pause>nul");
  274. system("cls");
  275. Main_Menu();
  276. }
  277. // Do while num equals to 1
  278. } while (num == 1);
  279. }
  280. }
  281. }
  282.  
  283. int Modify_Book_Details(void)
  284. {
  285. printf("***********************************************\n");
  286. printf("* Modify Book Details *\n");
  287. printf("***********************************************\n\n");
  288.  
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement