// This is the test program and question description for SYSC 2002 lab #2 version #2 (D2) // You are to write and submit files "LibraryCard.h" and "LibraryCard.cpp". // The following code and the sample executable should make it clear as to what methods are required and what they do. // You must, of course, create the necessary member variables (fields) for your LibraryCard class. // Note that the final version of the Date class (Date.h and Date.cpp) is provided on the G: drive for reference. #include "stdstuff.h" #include "LibraryCard.h" void realMain () { LibraryCard fred(10), mary, joe(30); // fred can take out up to 10 library books at a time // mary can take out the default number, i.e. 20, books at a time // joe can take out up to 30 library books at a time // Note that all the patrons start out with no library books borrowed. try { LibraryCard sue(-5); } catch (invalid_argument &e) { cout << "Invalid Argument Exception for sue <" << e.what() << "> occurred.\n\n"; } fred.borrowBooks(5); // fred borrows 5 books mary.borrowBooks(15); // mary borrows 15 books joe.borrowBooks(50); // joe tries to borrow 50 books, but this method has no effect as he is only allowed 30 try { fred.borrowBooks(-10); } catch (invalid_argument &e) { cout << "Invalid Argument Exception for fred <" << e.what() << "> occurred.\n\n"; } fred.returnBooks(3); // fred returns 3 books mary.returnBooks(10); // mary returns 10 books joe.returnBooks(5); // joe tries to return 5 books, but this method has no effect as he doesn't have 5 books to return try { fred.returnBooks(-2); } catch (invalid_argument &e) { cout << "Invalid Argument Exception for fred <" << e.what() << "> occurred.\n\n"; } cout << "Fred currently has "; fred.booksOut(); // should print 2 cout << " books.\nMary currently has "; mary.booksOut(); // should print 5 cout << " books.\nJoe currently has "; joe.booksOut(); // should print 0 cout << " books.\n\n"; cout << "Fred has borrowed " << fred.currentUsage() << "% of his maximum number of books.\n"; // currentUsage should return 20 cout << "Mary has borrowed " << mary.currentUsage() << "% of her maximum number of books.\n"; // currentUsage should return 25 cout << "Joe has borrowed " << joe.currentUsage() << "% of his maximum number of books.\n\n"; // currentUsage should return 0 // take out more books fred.borrowBooks(6); // fred borrows 6 books mary.borrowBooks(10); // mary borrows 10 books joe.borrowBooks(29); // joe borrows 29 books cout << "Fred currently has "; fred.booksOut(); // should print 8 cout << " books.\nMary currently has "; mary.booksOut(); // should print 15 cout << " books.\nJoe currently has "; joe.booksOut(); // should print 29 cout << " books.\n\n"; cout << "Fred has borrowed " << fred.currentUsage() << "% of his maximum number of books.\n"; // currentUsage should return 80 cout << "Mary has borrowed " << mary.currentUsage() << "% of her maximum number of books.\n"; // currentUsage should return 75 cout << "Joe has borrowed " << joe.currentUsage() << "% of his maximum number of books.\n\n"; // currentUsage should return 96.6667 } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }