Question: write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to

write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in the file has tile, au... Write a program to read a textfile containing a list of books. Each line in the file has tile, author and genre of a book separated by comma. After reading each line, you can use the parser function provided to separate those attributes and store them in the corresponding fields in the Book structure. All books should go into a vector of structures that you will create (similarly to the vector you created in lab1, except instead of a vector of double, you will need a vector of Book). It is ok to define the structure type in the global scope but all variables must be kept local. After the program reads the data from the file and stores all the books in a vector, have your program give the user options to see the books on the screen sorted by title, author or genre. Also add an option to quit. Use the sort function (#include ) to sort the requested data. Example: sort (myBooks.begin(), myBooks.end(), compareByTitle); sort will use the function that you provide to sort the data. Since you need to sort by three different fields, you will need three different compare functions. If the user asks to see the books sorted by title, you need to call sort passing compareByTitle. If he/she asks for the books sorted by author, you will need to call sort passing compareByAuthor, and so forth. Define one compare function for each option. This is how function compareByTitle should look like: bool compareByTitle(Book b1, Book b2) { return b1.title < b2.title) } After sorting, display all the information of each book in table format. No matter how the data is sorted, you should print all the fields. It is best to define a function that prints the whole vector. Print a header like the following and then all the data that is in the vector, one book per line. Title Author Genre

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!