Student and Book Management System
Student and Book Management System
In book management, a circular linked list is employed, where the `next` pointer of the last node points back to the `head`. This setup is used in functions like `addBookToStore` and `displayBooks`, facilitating easy iteration and insertions. The circular nature allows easy insertion at the end by simply connecting the new last node to `head`. Conversely, student management utilizes a doubly linked list, with separate `prev` and `next` pointers, allowing traversal in both directions and easier middle node insertion or deletion. The choice of data structure is influenced by operational needs; circular lists simplify simple cyclical operations, while doubly linked lists enhance complex insertions and deletions .
To implement a 'return book' feature, both the student and book management systems need to be updated. Structurally, a `bookBorrowDate` field could be added to track borrow durations. In the student record, the `bookBorrowed` field should handle multiple or zero values to support book returns. A function to check a student's borrowings, update their records on book return, and potentially move returned books back to the available list would be needed. Additionally, this function would adjust the book's availability status in the book linked list, potentially indicating a reversal of the `addBookToStore` process upon return .
The `deleteStudentById` function traverses the student list to locate the node with the specified ID. If found, it updates the `prev` and `next` pointers of the adjacent nodes to bypass the node being deleted. If the node to be deleted is at the head, `studHead` is moved to the next node; if it's at the tail, `studTail` is moved to the previous node. If the student is not found after full traversal, it prints "Student not found." .
The `studentMenu` functionality is preferred when a user-friendly interface is required to manage student data. It abstracts the complex function calls into a menu-driven system that sequentially guides users through options like adding, displaying, or deleting students with sequential input prompts. This design improves usability, reduces the likelihood of user errors associated with incorrect function usage, and allows for a more structured interaction with the data .
Student IDs are prefixed with 'UGR/', ensuring a standardized identifier format. This format aids in input validation during insertion and search operations, bolstering the integrity of records. Effective searching is realized through functions like `displayStudentById` and `deleteStudentById`, which traverse the linked list comparing user-inputted IDs with stored IDs to find the correct node. This search technique supports uniqueness by providing error feedback if duplicate IDs exist, thereby enforcing consistently unique entries across operations .
The `addBookAtMiddle` function uses target book identification to determine the insertion point. It takes a target Book ID as input and traverses the circular linked list starting from the head to find the node that matches this ID. Once located, a new book node is inserted right after this node by adjusting the `next` pointers. If the target Book ID is not found, the function prints an error message indicating that the Book ID was not found .
The `addStudentMiddle` function allows inserting a student at a specific position in a doubly linked list. It first checks if the list is empty; if it is, a student is added at the front using `addStudentFront()`. Otherwise, it traverses the list node by node until it reaches the specified position (starting from 1). If the position is beyond the current length of the list, the student is added at the end using `addStudentEnd()`. For insertion in the middle, the function updates the `prev` and `next` pointers of the adjacent nodes to include the new student node between them .
The `showBorrowed` function traverses the student linked list starting from `studHead`. For each student node, it retrieves and outputs the student's name and the book they borrowed in a simple format (e.g., `Student Name → Book Name`). This listing provides a summary of all borrowed books in association with the borrowers, displaying information until the end of the list is reached .
The `deleteBookById` function locates the book to be deleted by its Book ID. If the book is the only node, it deletes the head node and sets the head to NULL. If the target book is the head and there are multiple nodes, the last book's `next` pointer and `head` are updated to skip the current head. For other cases, it updates the previous node's `next` pointer to bypass the node being deleted. If the Book ID is not found, it informs the user that the ID was not found .
When displaying the list of students using `displayStudents`, the function must first check if the list is empty and inform the user if there are no students. Then, it iterates from `studHead` to `studTail`, printing the details of each student (ID, Name, Book Borrowed, Department, Year) followed by a separator. This ensures a comprehensive output of the list's contents .