Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 - the member function readBooks The member function readBooks populates an array of Book objects with the title and author data found in

Problem 1 - the member function readBooks The member function readBooks populates an array of Book objects with the title and author data found in a file similar to the file books.txt. The array of Book objects is one of the data members of the Library class.

This function should:

Accept one input argument: string: the name of the file to be read

Use ifstream, split(), and getline to read and parse data from the file.

For each line in the file: fill in the author and title data members for a Book object, at the appropriate index in the array of Book objects.

Also: Update the total number of books in the system(from all the files read so far, see the Important note below)

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

If the file contains more books than empty slots available in the books array, only write enough books so that you do not exceed the capacity of the array.

If the file cannot be opened, return -1

Important: when testing your readBooks function, make sure it supports multiple reads from different .txt files in a row. For example, you should be able to call the function to read the file books1.txt , and then call the function again to read the file book2.txt. The result should be an array of Book objects, with the books from the first file, followed by the books from the second file.

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions