Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a User class, with a separate interface (Book.h) and implementation (Book.cpp), comprised of the following attributes: fill an array of Book objects instead of

Create a User class, with a separate interface (Book.h) and implementation (Book.cpp), comprised of the following attributes:

fill an array of Book objects instead of having separate titles array and authors array. The functionality stays the same as the one from the previous homework. This function should:

  • Accept four input arguments in this order:

    • string fileName: the name of the file to be read.

    • array books: array of Book objects.

    • int numBooksStored: the number of books currently stored in the arrays. You can always assume this is the correct number of actual elements in the arrays.

    • int booksArrSize: capacity of the books array. The default value for this data member is 50.

  • Use ifstream and getline to read data from the file, making an instance of the Book object for each line, and placing it into the books array.

  • You can use the split() function from Problem 3 in Homework 6, with comma (,) as the delimiter. When you copy your code to the Coderunner, make sure you put in the Answer Box your Book class, readBooks() function, and split() function (if you are using it).

  • The function should return the following values depending on cases:

    • Return the total number of books in the system, as an integer.

    • When the file is not opened successfully, return -1.

    • When numBooksStored is equal to the size, return -2.

    • The priority of the return code -2 is higher than -1, i.e., in cases when numBooksStored is equal to the size and the file cannot be opened, the function should return -2.

    • When numBooksStored is smaller than size, keep the existing elements in books, then read data from the file and add (append) the data to the array. The number of books stored in the array cannot exceed the size of the books array.

  • Empty lines should not be added to the arrays

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

More Books

Students also viewed these Databases questions