CS 13A

                                    Homework #6 -Files

 

Create a file of library books called bookFile.  Each record contains three fields:  The title, the date the book was borrowed and the date the book was returned.  The main function displays the menu:

 

A) Add a book?

 

B) Display all books?

 

Q) Quit

 

If the user chooses “A”, then function addABook is called.  Function addABook opens bookFile as an append file, prompts the user for a title, date borrowed and date returned, and adds a record to bookFile.  The book title, date borrowed and date returned are written in the file with *’s between, and with an ‘&’ at the end.  The function then asks the user if another book is to be entered.  When the user no longer wants to add books, the file is closed.

 

If the user chooses “B” the function displayBooks is called.  Function displayBooks opens bookFile as an input file.  File bookfile is read and displayed.  In addition, the number of days the book was checked out is computed and displayed.  This requires two functions:  daysBetweenDates, and strToInt.  Function strToInt converts the strings: mm, dd, and yyyy to integers (the function is called three times).  The integers returned by strToInt are parameters for the daysBetweenDates function. 

 

 

 

First write the main function.

 

Second write addABook.

 

Third write displayBooks without calculating the days between dates.

 

Finally write strToInt, and calculate the days between dates.  Add this calculation to function displayBooks.