Subjects computer science

Library Checkout

Step-by-step solutions with LaTeX - clean, fast, and student-friendly.

Search Solutions

Library Checkout


1. **Problem Statement:** Design a Library Book Checkout system that allows a user to enter a 6-digit Library Card ID with a maximum of 4 attempts. If the ID is correct, repeatedly show a menu with options to view status, check out a book, return a book, or logout. --- ### Question 1 **a) Algorithm:** 1. Initialize attempt count to 0. 2. While attempt count is less than 4: - Prompt user to enter 6-digit Library Card ID. - If ID is correct, proceed to step 3. - Else, increment attempt count. 3. If 4 attempts are used without correct ID, display "Account Locked. Contact Staff." and end session. 4. Initialize current book count to 0. 5. Repeat until user selects Logout: - Display menu: 1. View Status 2. Check Out Book 3. Return Book 4. Logout - Get user choice. - If choice is 1, display current books checked out and remaining checkouts (max 5). - If choice is 2, if current book count < 5, prompt for ISBN and increment book count; else display "Checkout failed. Maximum limit (5) reached." - If choice is 3, if current book count > 0, prompt for ISBN and decrement book count; else display "Return failed. You have no books checked out." - If choice is 4, display "Thank you for using the Kiosk. Goodbye." and end session. **b) Pseudocode:** ``` attempts = 0 max_attempts = 4 max_books = 5 current_books = 0 correct_id = "123456" # example correct ID while attempts < max_attempts: input_id = input("Enter 6-digit Library Card ID:") if input_id == correct_id: break else: attempts += 1 if attempts == max_attempts: print("Account Locked. Contact Staff.") exit() while True: print("Menu:\n1. View Status\n2. Check Out Book\n3. Return Book\n4. Logout") choice = input("Select option:") if choice == '1': print(f"Books checked out: {current_books}") print(f"Remaining checkouts: {max_books - current_books}") elif choice == '2': if current_books < max_books: isbn = input("Enter ISBN to check out:") current_books += 1 print("Book checked out successfully.") else: print("Checkout failed. Maximum limit (5) reached.") elif choice == '3': if current_books > 0: isbn = input("Enter ISBN to return:") current_books -= 1 print("Book returned successfully.") else: print("Return failed. You have no books checked out.") elif choice == '4': print("Thank you for using the Kiosk. Goodbye.") break else: print("Invalid option. Please try again.") ``` **c) Flowchart Description:** - Start - Input Library Card ID - Decision: Is ID correct? - No: Increment attempts - Decision: Attempts < 4? - Yes: Loop back to input ID - No: Display "Account Locked. Contact Staff." and End - Yes: Initialize current_books = 0 - Loop Menu: - Display menu options - Input choice - Decision on choice: - 1: Display status, loop back - 2: Check if current_books < 5 - Yes: Input ISBN, increment current_books, loop back - No: Display "Checkout failed...", loop back - 3: Check if current_books > 0 - Yes: Input ISBN, decrement current_books, loop back - No: Display "Return failed...", loop back - 4: Display goodbye message, End - Else: Display invalid option, loop back --- ### Question 2 **Flowchart Description:** - Start - Input integer N - Initialize counter i = 1 - Loop while i <= 12: - Calculate product = N * i - Display "N x i = product" - Increment i by 1 - End --- This completes the answers for both questions.