CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

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.

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.