Question: C++ I need help redoing some code Update the readBooks function from Homework 6 to now fill an array of Book objects instead of having

C++ I need help redoing some code

Update the readBooks function from Homework 6 to now 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

C++ I need help redoing some code Update the readBooks function from

#ifndef BOOK_H #define BOOK_H #include using namespace std; class Book { private: string title; string author; public: Book(); Book(string title, string author); string getTitle() const; void setTitle(string title); string getAuthor() const; void setAuthor(string author); };

Homework 6 to now fill an array of Book objects instead of

#include "Book.h" Book::Book() {} Book::Book(string title, string author) : title(title), author(author) {} string Book::getTitle() const { return title; } void Book::setTitle(string title) { this->title = title; } string Book::getAuthor() const { return author; } void Book::setAuthor(string author) { this->author = author; } 

The split function

int split (string str, char c, string array [], int arrsize) { if (str.length() == 0) { // looks if lenght of string is 0 return 0; // returns 0 } string word = ""; // makes a string called word int j = 0; // creates a variable j makes it equal to 0 str = str + c; for (int i = 0; i

The other.cpp this needs to be edited

int readBooks(string filename, string titles[] , string authors[], int numbookstored, int size) { ifstream myfile; string line = ""; myfile.open(filename); string temp[2]; if (myfile.fail()) { return -1; // returns -1 } if(numbookstored == size) { return -2; // returns -2 } while(numbookstored Book.cpp: Book.cpp

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!