Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Starting out with c++, Tony Gaddis, technical Fundamentals of Database Systems, Elmarsi & Navathe, technical

The C++ Programming Language, Bjarne Stroustrup, technical

The Pillars of the Earth, Ken Follett, historical fiction

Fall of Giants, Ken Follet, historical fiction

Mindset: The New Psychology of Success, Carol Dweck, psychology

One Hundred Years of Solitude, Gabriel Garcia Marquez, fiction

Ashes, Kenzo Kitakana, fiction

The Dark Forest, Liu Cixin, science fiction

Replay, Ken Grimwood, fantasy

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

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

What is the per-capita cost?

Answered: 1 week ago

Question

Contrast feedforward, concurrent, and feedback controls.

Answered: 1 week ago

Question

soriano company is preparing its master budget

Answered: 1 week ago

Question

3. How frequently do the assessments occur?

Answered: 1 week ago