Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code must be in c++ Question 1(55 pts): Implement the following classes: A) (15 pts) class Book with the following members: 1. private members: a.

code must be in c++
image text in transcribed
image text in transcribed
image text in transcribed
Question 1(55 pts): Implement the following classes: A) (15 pts) class Book with the following members: 1. private members: a. book title (string) b. book ISBN (string) c. book first author (string) d. book number_of_copies (int) Note: for this assignment, a book ISBN can be any string (such as 978-3-16) and it should be unique for each book. 2. public members: a. A parameterized constructor with default arguments for all data members: *-* for the string data members and for the numeric data member. The constructor should initialize all data members properly b. setters and getters for all data members. The setter for the number of copies should validate that the number is greater than or equal to zero, and for strings to be non-empty. C. The member function updateBookNumCopies(int n) to update the number of copies of a book. The function receives an integer value (can be negative or positive) and updates the current number of copies only If the result of adding that value to the current count is zero or more, otherwise, it prints a proper error message. the current count is zero or more, otherwise, it prints a proper error message. B) (40 pesclass Library where a library contains several books that can be added or removed Implement class Library with the following: 1. Three prihvate data member a int maxSize that represents the maximum number of books (.e., unique book titles) that can be added to the brary. Note that you can add any number of copies of a given book int current that tracks the current number of unique book titles in the library, this attribute gets updated whenever a new book title is removed or added to the library cBook "bookList a pointer to a dynamic anay of Books that represent all unique book titles in the library 2. The private member function vold resizeLibrary in which resizes the dynamic anay pointed to by the pointer bookList The function should increase the array capacity by the amount of The function should validate that is a positive Integer The function must preserve the data that was already in the list. 3. The following public member functions Lise this pointer in all member functions of the class that take one marameters Libraryfinns that sets maxSize ton, allocates dynamic space of size maxSize, and makes the booklist pointer points to the allocated space and sets current to b. A copy constructor Library(const Library 8) to properly copy data from one Library object to another -Libraryo: Deallocates any dynamically allocated memory for an object. disEmpty), a boolean function that returns true if the library is empty and false otherwise eisFull) a boolean function that returns true if the library is full, and false otherwise intfindBook By Titleconst string & title) returns the index of the book with requested title if found in the library, otherwise return-1. HINT use a string compare function (strcmp) from the string library #intfindBookBy:SBN(string isbn) returns the index of the book with an ISBN that is equal to isbn il found in bookList otherwise returns-1 void addBook const Book & book} this function does the following adds the book to the end of list bookList if the Library is not full and the book does not already exist in the list if the book to is already in the list then update the number of copies of that book (increment the current number of copies by the amount wher_of_copie If a book is not in the list, but the list is full, then resize the library pointed by booklist to allow for 10 more books then add the book at the first aitable location fie. after all the books that already exist vold addBook): this functions similar to the previous method but this one asks for all required book data to be input by the use of your program Getters for maxSize and current data members k float capacity Usage that calculates the percentage of the maximum number of books filled with books. The dision must be a floating point division bool removeBookCopy(string isbn if the book exists in the library then decrements the number of copies of the book by one of the number of copies becomes zero, the function must delete the book from the list by shifting left all book items on the right of the book to be removed. the function return true if the book is found, otherwise, prints a proper mesage and return false 4. Define a global friend function void printLibrary(const Library & libr) that recentes a Library object and prints the information of all the books in that library Note: You may implement additional methods if you need to Question 2 (35 pts): Write a driver program to test the classes you have implemented as follows: Note: Do not reimplement functionalities that are already implemented in classes Book and Library. 1. Create a dynamic array of Book objects named myBooks_items of size 5. 2. Fill myBooks_items with proper data from the user for 5 different books. 3. Create a Library object named lib with a maxSize of 6. 4. Fill the first 5 items of the library lib using the book items from myBooks_items array. 5. Create a dynamic object of type Book using the data of the second object in the array myBooks_items 6. Delete the dynamic array pointed to by myBooks_items 7. Add 3 more copies of the book from Question2-point 5 to library lib 8. Add two more unique books by calling addBook() 9. display the details of all books in lib 10. call a proper function to print the current size of the library 11. Print the usage-percentage of the bookList in lib using a proper function call. 12. remove all copies of the book from Question2-point 5. 13. Once again, Display the details of all the books in lib

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions