Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ the question is write 2 classes Question 1(55 pts): Implement the following classes: A) [15 pts] class Book with the following members: 1.

using c++

the question is write 2 classes

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 0 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 nonempty. 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. B) [40 pts] class Library where a library contains several books that can be added or removed. Implement class Library with the following: 1. Three private data members: a. int maxSize that represents the maximum number of books (i.e., unique book titles) that can be added to the library. Note that you can add any number of copies of a given book. b. 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. c. Book *bookList, a pointer to a dynamic array of Books that represent all unique book titles in the library. 2. The private member function void resizeLibrary(int n), which resizes the dynamic array pointed to by the pointer bookList. a. The function should increase the array capacity by the amount of n. b. The function should validate that n is a positive integer. c. The function must preserve the data that was already in the list. 3. The following public member functions: Use this pointer in all member functions of the class that take one or more parameters. a. Library(int n): that sets maxSize to n, allocates dynamic space of size maxSize, and makes the bookList pointer points to the allocated space. and sets current to 0. b. A copy constructor Library(const Library &) to properly copy data from one Library object to another. c. ~Library(): Deallocates any dynamically allocated memory for an object. 3 d. isEmpty(), a boolean function that returns true if the library is empty. and false otherwise. e. isFull(), a boolean function that returns true if the library is full, and false otherwise. f. int findBookByTitle(const string & title) returns the index of the book with requested title if found in the library, otherwise returns -1. HINT: use a string compare function (strcmp) from the string library. g. int findBookByISBN(string isbn) returns the index of the book with an ISBN that is equal to isbn if found in bookList, otherwise returns -1. h. 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 is 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 number_of_copies) 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 available location (i.e., after all the books that already exist). i. void addBook(): this function is similar to the previous method but this one asks for all required book data to be input by the user of your program. j. Getters for maxSize and current data members. k. float capacityUsage() that calculates the percentage of the maximum number of books filled with books. The division must be a floating-point division l. bool removeBookCopy(Library& libr, string isbn): if the book exists in the library then decrements the number of copies of the book by one If 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 returns true if the book is found, otherwise, prints a proper message and returns false. 4. Define a global friend function void printLibrary(const Library & libr) that receives a Library object and prints the information of all the books in that library.

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

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

With your help we will soon begin.

Answered: 1 week ago