Question: Assignment: Managing Books, Part 2 in C++ Part 1 Instructions In the previous assignment, we created a class called Book, which stored basic information about

Assignment: Managing Books, Part 2 in C++

Part 1 Instructions In the previous assignment, we created a class called Book, which stored basic information about a book at a library. The program used this class to create sample book objects to store information about popular novels. In this program, we are going to build a new class called Catalog, which will be used to store and manage books in the library. The program should support the following menu commands: 1. Search Catalog a. By Title b. By ISBN 2. List Books by Author 3. Add New Book 4. Get Book Status 5. Check in a Book 6. Check Out a Book 7. Exit

Descriptions of Notable Methods 1. listBookByAuthor prints out a list of books written by the author. Returns true if the author has at least 1 book in the catalog and false if not. 2. getBookBy - These methods search the Catalog for a book matching the specified attribute. The book parameter is a reference parameter used to pass the book back by. If the book is found, assign the book parameter to the book found and return true. If not found, do not assign the book object to anything, and return false. 3. checkOutBook Searches the catalog of the book for the ISBN number and checks the book out, if the book is found and is not checked out. Returns true if it successfully checks the book out, false if it does not. 4. checkInBook Checks in a book in the catalog. Returns true if the book is found and checked in, and false otherwise. 5. addBook Adds a book to the catalog. Takes in a book object and then copies that book object into the next available slot. If the books array is at capacity, then growCatalog() should be called. 6. outputCatalog Prints out the entire catalog of books. Calls the outputBook method from each book. 7. growCatalog This function will be provided to you in the Appendix. This function should be copied into your Catalog class definition. Used to increase the number of elements in the books array to support more books. Check Appendix A for the solution to this function. 8. emptyCatalog This function deallocates all book objects in the books array. Use delete[] on the array to achieve this. Hints 1. Start by creating the class definition first. Implement the methods in the class definition before working on the .cpp file. 2. Test each method individually in the main function before writing the code for the menu. Create a Catalog object to work with and add random books to the catalog. Call the methods and observe how they behave to test the Catalog class. Tip: You may add additional helper methods to your Catalog. One method you might add is the ISBN search method from Program 3 to determine the index location of a book in the array. This might be useful for check in and check out methods. 3. Once you feel confident the Catalog class works, begin working on the menu code. You may use either an if/else if statement or switch statement to decide what menu item is chosen. 4. Test each menu command to ensure they work.

Catalog

-books: Book pointer

-next_slot: int

-capacity: int

Catalog(init_size: int)

~Catalog()

Getters and Setters

+getNumBooks(): int

-emptyCatalog(): void

Utility Methods

+getBookByTitle(title:string, book: Book&): bool

+listBooksByAuthor(author:string): bool

+getBookByISBN(isbn:int, book:Book&): bool

+checkOutBook(isbn:int, name:string): bool

+checkInBook(isbn: int): bool

+addBook(new_book: Book): void

+outputCatalog(): void

-growCatalog(): void

===============

BookClass.h

#pragma once #include #include

using std::cout; using std::endl; using std::string;

class Book { private: string title; string author; int ISBN; bool isCheckedOut; string checkedOutBy;

public: //Constructor Book(string t = "N/A", string a = "N/A", int i = -1) { title = t; author = a; ISBN = i; isCheckedOut = false; checkedOutBy = ""; }

//Getters string getTitle() { return title; } string getAuthor() { return author; } int getISBN() { return ISBN; } bool getStatus() { return isCheckedOut; } string getCheckedOutBy() { return checkedOutBy; }

//Setters void setTitle(string new_t) { title = new_t; } void setAuthor(string new_a) { author = new_a; } void setISBN(int new_i) { ISBN = new_i; }

// If the book is checked out, return false, //otherwise, set the checked out status to //true and update the name of the user that //checked out the book. bool checkOutBook(string n) { if (isCheckedOut == true) return false; else { isCheckedOut = true; checkedOutBy = n; return true; } }

void returnBook() { isCheckedOut = false; checkedOutBy = ""; }

void outputBook() { cout << title << endl; cout << " by " << author << endl; cout << " ISBN: " << ISBN << endl;

if (isCheckedOut == true) { cout << " Checked out By: " << checkedOutBy << endl; } }

//Add built in support for the assignment operator //i.e. Book myBook = book_oj; Book& operator=(const Book& obj) { if (this == &obj) return *this;

this->author = obj.author; this->title = obj.title; this->ISBN = obj.ISBN; this->checkedOutBy = obj.checkedOutBy; this->isCheckedOut = obj.isCheckedOut;

return *this; } };

==============

TestCatalogClass_Skeleton.cpp

#include "CatalogClass.h" #include

using std::cin; using std::getline;

void populate_catalog(Catalog& my_catalog); int display_menu();

int main() { Catalog my_catalog; populate_catalog(my_catalog);

cout << "Welcome to the Library! "; int choice = 0;

do { cout << " "; choice = display_menu(); cout << " ";

/* **************************************************** Your solution for the menu commands goes here. **************************************************** */

} while (choice >= 1 && choice < 8);

return 0; }

int display_menu() { int choice; do { cout << "Main Menu "; cout << "1. Search by Book Title "; cout << "2. Search by Book ISBN "; cout << "3. Output all books by Author "; cout << "4. Add a New Book to the Catalog "; cout << "5. Get Check Out Status of Book "; cout << "6. Check in a book "; cout << "7. Check out a book "; cout << "8. Exit Program ";

cout << "Enter your choice: "; cin >> choice;

if (choice < 1 and choice > 8) { cout << "Error: Not a valid Selection! "; }

} while (choice < 1 || choice > 8);

return choice;

}

void populate_catalog(Catalog& my_catalog) { Book temp_obj; temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Sorcerers Stone"); temp_obj.setISBN(98346); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Chamber of Secrets"); temp_obj.setISBN(19285); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Prisioner of Azkaban"); temp_obj.setISBN(88224); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Goblet of Fire"); temp_obj.setISBN(21001); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Order of Phoenix"); temp_obj.setISBN(66754); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Half-Blood Prince"); temp_obj.setISBN(50125); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("J.K. Rowling"); temp_obj.setTitle("Harry Potter and the Deathly Hallows"); temp_obj.setISBN(68304); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("The Lion, the Witch, and the Wardrobe"); temp_obj.setISBN(45336); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("Prince Caspian"); temp_obj.setISBN(76689); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("The Voyage of the Dawn Treader"); temp_obj.setISBN(34982); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("The Silver Chair"); temp_obj.setISBN(45993); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("A Horse and His Boy"); temp_obj.setISBN(42398); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("The Magician's Nephew"); temp_obj.setISBN(39203); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("C.S. Lewis"); temp_obj.setTitle("TheLast Battle"); temp_obj.setISBN(56342); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("E. B. White"); temp_obj.setTitle("Charlotte's Web"); temp_obj.setISBN(47851); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("F. Scott Fitzgerald"); temp_obj.setTitle("The Great Gasby"); temp_obj.setISBN(11934); my_catalog.addBook(temp_obj);

temp_obj.setAuthor("S. E. Hinton"); temp_obj.setTitle("The Outsiders"); temp_obj.setISBN(72331); my_catalog.addBook(temp_obj);

/* Feel free to add more books below to experiment with the catalog class! */ }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!