Patron Book Lists
Introduction
A public library allows residents to check out up to five books at a time. Assuming the town is small, everyone is known by name, so only a person's name, the number of books, and the due date are stored. (No need to keep track of addresses or telephone numbers—that information is well known throughout the town.) In support of this application, we will store the relevant data on a singly-linked list using the following node declarations:
#define MAX_STRING_LEN 128
#define MAX_NUM_BOOKS 4
struct patronRecord {
char name[MAX_STRING_LEN];
int numBooksBorrowed;
char booksBorrowed[MAX_NUM_BOOKS][MAX_STRING_LEN];
char dueDate[MAX_STRING_LEN];
struct patronRecord* next;
}
To make processing easy (at least for this problem), a resident
checks out up to MAX_NUM_BOOKSbooks with a common due
date. Further checkouts are not allowed, until all previous books
are returned. Residents can inquire about what books they have
checked out at any time.
Details
Processing notes
The main menu for working with residents and checked-out books is as follows:
Library checkout options:
c: check out 1-4 books (but only if resident has no books currently checked out)
p: print all residents with checked out books
s: search the checkout list for a given resident,
printing the resident's name, books checked out (if any), and due date
r: return a book, given resident's name and book title
q: quit
When a resident checks out books, the titles are stored as rows in
the booksBorrowed array. For convenience in printing,
the titles are all in the first rows of the table. If the resident
has not borrowed the maximum number of books, the last rows are left
blank.
When a resident wants to check out books (option c), the list is searched. If the resident has no books outstanding, a new node is created for the resident. For efficient insertion, this node should be added at the front of the linked list. (For example, one might use the approach of Scheme-like lists.)
Printing (option p) should display resident names with checked out books, the books they have borrowed, and the common due date. The resident's records may appear in any order. However, printing should not change the list itself.
Some residents inquire often about their checked-out books, and some residents ask rarely. Thus, in improve efficiency for curious residents, whenever a search for a resident (option s) is performed, the resident's record is moved one node closer to the front of the list. (Assuming the resident has checkout books to find. If the resident's name is already first, the list is not changed.) This movement of nodes will help ensure that commonly accessed nodes stay near the front of the list.
When a book is returned (option r), the book title is removed from the resident's record in the node.
- If other books remain checked out, the book titles are moved down in the two-domensional array. so they are all together as the first rows of the table.
- If no other books remain checked out, the resident's record is removed from the list.
Each menu option for this problem (except quit) should be performed by a separate function. (Helper functions are allowed. As long as the main program calls a function for each menu option, processing may be organized in whatever way seems appropriate.
Global variables may not be used in this problem. (Each declaration of a global variable will yield a 15 point penalty, so the use of two global variables guarantees 0 points for this problem.)
Grading
In addition to the general grading guidelines for evaluation, the assignment is worth 25 points.
- [5 points] Checks out books correctly
- [2 points] Program searches list for matching patron
- [3 points] New patron records are inserted at the list front
- [3 points] Prints all patron records completely
- [6 points] Search prints results and advances record
- [2 points] Search finds and prints patron record
- [4 points] If not first, search advances record node within list
- [5 points] Returns books correctly
- [2 points] Shifts array elements if books remain
- [3 points] Patron record deleted if no books remain
- [6 points] Tests demonstrate correctness
- [2 points] Test plan enumerates the range of problem circumstances
- [2 points] Test cases include specific inputs and expected outcome(s)
- [1 point] Transcripts demonstrate functionality with test runs
- [1 point] Statement argues why the program is correct
-
Comments on Program Format, Comments, Readability, etc.
(Points not given, but points can be deducted.)
