Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *Progamer's Name: Dillon Bong Zi Hang
- *Program Description: Library Management System Login Menu
- *Last Updated: 24 - January - 2016
- */
- // Header File
- #include"LMS_Header.h"
- /* Library Management System Login Menu */
- int main(void)
- {
- // Label A for invalid input in Login
- A:
- // Get username and password and ignore whitespace
- printf("***********************************************\n");
- printf("* Library Management System *\n");
- printf("***********************************************\n\n");
- printf("Username: ");
- scanf("%s", &u);
- fflush(stdin);
- printf("\nPassword: ");
- scanf("%s", &p);
- fflush(stdin);
- // Entered username and password is equal to Admin
- if ((stricmp(username, u)) == 0 && (strcmp(password, p)) == 0)
- {
- // Login success from login menu. Go to Main Menu
- {
- printf("\nLogin Successful\n\n");
- system("pause");
- system("cls");
- Main_Menu();
- }
- }
- else
- {
- // Login failed from login menu. Re-enter username and password
- printf("\nLogin Failed\n\n");
- system("pause");
- system("cls");
- goto A;
- }
- system("pause>nul");
- return 0;
- getch();
- }
- /* Library Management System Main Menu */
- Main_Menu(void)
- {
- printf("***********************************************\n");
- printf("* Main Menu *\n");
- printf("***********************************************\n\n");
- printf("1. Add New Book\n");
- printf("2. Modify Book Details\n");
- printf("3. Remove Book\n");
- printf("4. View Book List\n");
- printf("5. Book Check In\n");
- printf("6. Book Check Out\n");
- printf("7. Search Menu\n");
- printf("8. View Logs\n");
- printf("9. Exit\n\n");
- printf("Please select an option: ");
- {
- // Gets user's option
- gets(main_menu_option);
- // if user confirmation's string length is equal to 1
- if (strlen(main_menu_option) == 1)
- {
- switch (main_menu_option[0])
- {
- // Goto Add New Book Menu
- case '1':
- fflush(stdin);
- system("cls");
- Add_New_Book();
- break;
- // Goto Modify Book Details
- case '2':
- fflush(stdin);
- system("cls");
- Modify_Book_Details();
- break;
- case '3':
- printf("");
- break;
- case '4':
- printf("");
- break;
- case '5':
- printf("");
- break;
- case '6':
- printf("");
- break;
- case '7':
- printf("");
- break;
- case '8':
- printf("");
- break;
- case '9':
- // Terminating the Program
- printf("\nProgram will now terminate. Press any key to continue");
- system("pause>nul");
- exit(0);
- break;
- default:
- // Invalid Input from the user
- printf("\nInvalid input please re-enter an option");
- system("pause>nul");
- system("cls");
- Main_Menu();
- break;
- }
- }
- else
- {
- printf("\nInvalid input please re-enter an option");
- system("pause>nul");
- system("cls");
- Main_Menu();
- fflush(stdin);
- }
- }
- }
- /* Add New Book Menu */
- void Add_New_Book(void)
- {
- struct Books_Data t;
- {
- // Open Book Data Text File in append or create binary mode
- file_pointer = fopen("Book Data.dat", "ab");
- // If file is unable to open, then display error
- if (file_pointer == NULL)
- {
- printf("\nFile cannot be opened.");
- system("pause>nul");
- system("cls");
- Main_Menu();
- }
- else
- {
- printf("***********************************************\n");
- printf("* Add New Book *\n");
- printf("***********************************************\n\n");
- // Accept Book ID as input
- printf("1. Book ID: ");
- gets(t.Book_ID);
- fflush(stdin);
- // Accept Book Title as input
- printf("\n2. Book Title: ");
- gets(t.Book_Title);
- fflush(stdin);
- // Accept Book Edition as input
- printf("\n3. Book Edition: ");
- gets(t.Book_Edition);
- fflush(stdin);
- // Accept Year of Publication as input
- printf("\n4. Year of Publication: ");
- gets(t.Year_of_Publication);
- fflush(stdin);
- // Accept Shelf Location as input
- printf("\n5. Shelf Location: ");
- gets(t.Shelf_Location);
- fflush(stdin);
- // Accept Price as input
- printf("\n5. Price(RM): ");
- gets(t.Price);
- fflush(stdin);
- // Do loop to confirm data
- printf("\nConfirm (y/n)? Type esc to return to Main Menu: ");
- do
- {
- // Set num equals to 0
- num = 0;
- gets(add_new_book_confirm);
- fflush(stdin);
- // Compare user input to escape
- if (stricmp(add_new_book_confirm, escape) != 0)
- {
- // if user confirmation's string length is equal to 1
- if (strlen(add_new_book_confirm) == 1)
- {
- switch (add_new_book_confirm[0])
- {
- // Save all data into file
- case 'y':
- {
- fwrite(&t, sizeof(t), 1, file_pointer);
- fclose(file_pointer);
- fflush(stdin);
- num1 = 0;
- printf("\nRecord Successfully Added. Add new book (y/n): ");
- // Do loop to get add new book input
- do
- {
- gets(add_more_book_confirm);
- fflush(stdin);
- if (strlen(add_more_book_confirm) == 1)
- {
- switch (add_more_book_confirm[0])
- {
- case 'y':
- system("cls");
- Add_New_Book();
- break;
- case 'n':
- system("cls");
- Main_Menu();
- break;
- default:
- fflush(stdin);
- printf("\nInvalid input. Please Re-Enter Confirmation to Add New Book: ");
- num1++;
- }
- }
- else
- {
- fflush(stdin);
- printf("\nInvalid input. Please Re-Enter Confirmation to Add New Book: ");
- num1++;
- }
- } while (num1 == 1);
- break;
- }
- // Return to Add New Book Menu
- case 'n':
- {
- fflush(stdin);
- fclose(file_pointer);
- system("cls");
- Add_New_Book();
- break;
- }
- // Invalid Input. Re-enter user confirmation and increment 1 to num
- default:
- {
- fflush(stdin);
- printf("\nInvalid input. Please Re-Enter Confirmation: ");
- num++;
- break;
- }
- }
- }
- else
- {
- // Invalid Input. Re-enter user confirmation and increment 1 to num
- printf("\nInvalid input. Please Re-Enter Confirmation: ");
- num++;
- }
- }
- // User input equals to esc then return to main menu
- else if (stricmp(add_new_book_confirm, escape) == 0)
- {
- fclose(file_pointer);
- printf("\nThe program will now return to Main Menu");
- system("pause>nul");
- system("cls");
- Main_Menu();
- }
- // Do while num equals to 1
- } while (num == 1);
- }
- }
- }
- int Modify_Book_Details(void)
- {
- printf("***********************************************\n");
- printf("* Modify Book Details *\n");
- printf("***********************************************\n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement