Next: About this document
Make a copy of the library program (~taw2/pub/library.c
) and
add the following functionality to it:
- Add an operation to print an entire library. The user should be
allowed to choose whether the library is printed to the screen or to
a text file. The owner and size of the library should be printed,
followed by each of the books in the library.
- Add an operation to sort an entire library.
After sorting, the books should be ordered alphabetically by author.
Assume that all author fields start with the last name
of the author. Use the function
strcmp
from <string.h>
for
comparing author fields. - Add an operation for deleting a book. The book to be deleted should
be specified by author and title. Again,
strcmp
will be useful.
If no book with the specified author and title exists in the library,
your code should print an error message and not change the library.
Hint: if the book to be deleted is the last book in the array, just
reduce the size of the array (the lib_size
field of the
librarytype
struct
) by 1. Otherwise, swap the last book in
the array with the book to be deleted and reduce the size of the array
by 1. - Add a user interface that allows users of your program to
choose which library operation they would like to apply from a menu of
choices. All of the operations on a library (those you implemented and
those I provided) should be available through this menu. Function
initlibrary
should be called before this menu is displayed the first
time to set up the library. - For 5 points extra credit, add an operation for reading a library
from a text file. You can assume that the text file will be in whatever
format you used for printing a library to a file.
- To hand in:
- Either turn in a print out of your source code, or email me
(wahls@psu.edu) the file containing your source code.
If you email me the program, I will email you your score and any comments
on your program sometime after the due date. I will also save a copy of
your program to prevent later disputes.
- Your code will be graded on correctness, programming style,
readability, the clarity
of messages printed for the user and appropriate use of comments.
Next: About this document
Tim Wahls
Wed Apr 2 11:30:09 EST 1997