Pages

Thursday, 14 June 2018

Chapter 9 // Exercise 9 - Principles & Practice Using C++

In this exercise I am using Visual Studio Community 2017 and the header file "std_lib_facilities.h" which can be found here:

http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h


Chapter 9 // Exercise 9



Create a Library class. Include vectors of Books and Patrons. Include a struct called Transaction. Have it include a Book, a Patron, and a Date from the chapter. Make a vector of Transactions. Create functions to add books to the library, add patrons to the library, and check out books. Whenever a user checks out a book, have the library make sure that both the user and the book are in the library. if they aren't, report an error. Then check to make sure the the user owes no fees. if the user does, report and error. If not, create a Transaction, and place it in the vector of Transactions. Also write a function that will return a vector that contains the names of all the Patrons who owe fees.

Link to Project:
Exercise 9 Project


This exercise has been provided as the full project as there are several different files included. It has been separated into the following classes:

  • Book Class
  • Date Class (based off the last drill in exercise 9)
  • Patron Class
  • Library Class
  • Main
The Book, Date and Patron classes can only be accessed from within the Library class. The library class is created in main() in which books can be checked out by passing the ISBN number of the book and the card number of the patron. 

The error checking isn't great but it works for the scenario he has given us. I also refrained from adding extra features that he hadn't explicitly laid out in the exercise. 

You can create a library class in main() and from there 3 functions are available: checkOutBook(isbn, cardNum), printFeesOwed() and printLibrary().

checkOutBook(isbn, cardNum) takes in an isbn in the format n-n-n-x and a set of numbers and checks to see if these correspond with books and patrons added to the library. If they do and the patron has no fees it creates a transaction. If they don't match or the patron has a fee, no transactions are created and an error message is displayed.

New books and patrons can be added to the library, however currently they must be hard-coded in. Although it would be easy to create a new function in library which takes in the required fields and creates a new book. The same can be done with patrons.

I tried not to go to crazy on this, although I kind of wanted to.

No comments:

Post a Comment