The New York Times newspaper has published “best seller” lists since 1942. Book sales are tracked nationwide, leading to a list of those books which have recently sold the most copies. You will design, implement and test a C++ program which allows the user to search a subset of the books which have appeared in the New York Times best seller lists. For simplicity, the data set will only contain those books which have reached #1 on either of two lists (fiction and nonfiction) since 1942. The file included named bestsellers.txt contains the complete data set. Each line of the file contains the information for a separate book, which includes: title, author, publisher, date it first reached #1 on one of the best seller lists, and category (fiction or nonfiction). There is a tab character ('\t') between fields. Add a BestSellers class that contains a single attribute of a vector of Book objects, an addBook method that receives a Book object and adds it to the vector, and a display method that contains a for loop to display all the Book objects' data in the same format you used in Lab9Quiz. Your main function should do the following: Create a BestSellers object Read the file and for each line of data read do the following: Create a Book object using the data read Add the Book object to the vector of books objects in the BestSellers class by calling the addBook method on the BestSellers object. you created. After the entire file is read, the program will display a menu of options and allow the user to search for books which meet certain criteria. The menu options are: Display all books in a particular year: Prompt the user for a year, then display all books which reached the #1 spot in that year. Search for an author: Prompt the user for a string, then display all books whose author’s name exactly matches the string. File bestsellers.txt is screenshotted below

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In C++.

The New York Times newspaper has published “best seller” lists since 1942. Book sales are tracked nationwide, leading to a list of those books which have recently sold the most copies.

You will design, implement and test a C++ program which allows the user to search a subset of the books which have appeared in the New York Times best seller lists. For simplicity, the data set will only contain those books which have reached #1 on either of two lists (fiction and nonfiction) since 1942.

The file included named bestsellers.txt contains the complete data set. Each line of the file contains the information for a separate book, which includes: title, author, publisher, date it first reached #1 on one of the best seller lists, and category (fiction or nonfiction). There is a tab character ('\t') between fields.

Add a BestSellers class that contains a single attribute of a vector of Book objects, an addBook method that receives a Book object and adds it to the vector, and a display method that contains a for loop to display all the Book objects' data in the same format you used in Lab9Quiz.

Your main function should do the following:
Create a BestSellers object
Read the file and for each line of data read do the following:
Create a Book object using the data read
Add the Book object to the vector of books objects in the BestSellers class by calling the addBook method on the BestSellers object. you created. After the entire file is read, the program will display a menu of options and allow the user to search for books which meet certain criteria. The menu options are:

  1. Display all books in a particular year: Prompt the user for a year, then display all books which reached the #1 spot in that year.

  2. Search for an author: Prompt the user for a string, then display all books whose author’s name exactly matches the string.

  3. File bestsellers.txt is screenshotted below
bestsellers 2.txt
4/11/1976
11/27/2011
Helen Hooven Santmeyer
1876
Gore Vidal
Random House
Fiction
Stephen King
...and Ladies of the Club
Scribner.
23337
Fiction
7/8/1984
Fiction
Putnam
Fiction
James Patterson Little, Brown
James Patterson Little, Brown
James Patterson Little, Brown
James Patterson Little, Brown
Lee Child
1st to Die
2nd Chance
3/25/2001
3/24/2002
3/21/2004
5/22/2005
6/6/2010
Fiction
Fiction
Fiction
Fiction
10/16/2005
S 3rd Degree
4th of July
61 Hours
Delacorte
y
Diana Gabaldon Pelacorte
Viking 4/29/2001
A Breath of Snow and Ashes
A Common Life
A Dance With Dragons
A Day Late and a Dollar Short
A Feast For Crows
A Lion Is In the Streets
A Man In Full
A Painted House John Grisham
A Perfect Spy
A Rage to Live
A Shade of Difference
A Thousand Splendid Suns
A Tree Grows In Brooklyn
A Widow For One Year
Accident
Fiction
Jan Karon
Fiction
George R. R. Martin
Bantam
7/31/2011
Fiction
ho
Fiction
Fiction
Terry McMillan Viking 2/4/2001
George R. R. Martin
11/27/2005
McGraw
Bantam
Adria Locke Langley
Farrar, Straus & Giroux 11/22/1998
Doubleday
Knopf
Random House
7/1/1945
Fiction
Tom Wolfe
Fiction
in
2/25/2001
Fiction
Lal
John le Carre
5/4/1986
Fiction
John 0'Hara
9/18/1949
Fiction
Allen Drury
Doubleday
Khaled Hosseini Riverhead
10/28/1962
Fiction
6/10/2007
Fiction
Betty Smith
Harper
1/2/1944
6/14/1998
Fiction
John Irving
Danielle Steel Delacorte
Random House
Fiction
2/27/1994
8/24/2008
Ernest Hemingway
Fiction
Acheron Sherrilyn Kenyon
Across the River and Into the Trees
St. Martin's
Fiction
Scribner's
10/15/1950
Fiction
Allen Drury
Tom Clancy
Michael Crichton
Advise and Consent
Doubleday
Putnam
10/4/1959
Fiction
Against All Enemies
Airframe
7/3/2011
12/29/1996
Fiction
Knopf
4/7/1968
Fiction
Airport Arthur Hailey
Doubleday
Fiction
Transcribed Image Text:bestsellers 2.txt 4/11/1976 11/27/2011 Helen Hooven Santmeyer 1876 Gore Vidal Random House Fiction Stephen King ...and Ladies of the Club Scribner. 23337 Fiction 7/8/1984 Fiction Putnam Fiction James Patterson Little, Brown James Patterson Little, Brown James Patterson Little, Brown James Patterson Little, Brown Lee Child 1st to Die 2nd Chance 3/25/2001 3/24/2002 3/21/2004 5/22/2005 6/6/2010 Fiction Fiction Fiction Fiction 10/16/2005 S 3rd Degree 4th of July 61 Hours Delacorte y Diana Gabaldon Pelacorte Viking 4/29/2001 A Breath of Snow and Ashes A Common Life A Dance With Dragons A Day Late and a Dollar Short A Feast For Crows A Lion Is In the Streets A Man In Full A Painted House John Grisham A Perfect Spy A Rage to Live A Shade of Difference A Thousand Splendid Suns A Tree Grows In Brooklyn A Widow For One Year Accident Fiction Jan Karon Fiction George R. R. Martin Bantam 7/31/2011 Fiction ho Fiction Fiction Terry McMillan Viking 2/4/2001 George R. R. Martin 11/27/2005 McGraw Bantam Adria Locke Langley Farrar, Straus & Giroux 11/22/1998 Doubleday Knopf Random House 7/1/1945 Fiction Tom Wolfe Fiction in 2/25/2001 Fiction Lal John le Carre 5/4/1986 Fiction John 0'Hara 9/18/1949 Fiction Allen Drury Doubleday Khaled Hosseini Riverhead 10/28/1962 Fiction 6/10/2007 Fiction Betty Smith Harper 1/2/1944 6/14/1998 Fiction John Irving Danielle Steel Delacorte Random House Fiction 2/27/1994 8/24/2008 Ernest Hemingway Fiction Acheron Sherrilyn Kenyon Across the River and Into the Trees St. Martin's Fiction Scribner's 10/15/1950 Fiction Allen Drury Tom Clancy Michael Crichton Advise and Consent Doubleday Putnam 10/4/1959 Fiction Against All Enemies Airframe 7/3/2011 12/29/1996 Fiction Knopf 4/7/1968 Fiction Airport Arthur Hailey Doubleday Fiction
1 #include "Book.h"
2 #include "BestSellers.h"
3 #include <fstream>
4 #include <iostream>
5 using namespace std;
6 int main()
7 { BestSellers BestBooks;
fstream fileIn("bestsellers.txt",ios::in);
if (!fileIn)
{cout <« "No open"
return 1;}
string a,t,p,d,c;
int choice=0;
getline(fileIn,t,'\t'); // prime read of first title in file
while (!fileIn.eof())
{ getline(fileIn, a, '\t');
getline(fileIn,p,'\t');
getline(fileIn,d,'\t');
getline(fileIn,c);
Book b(t,a,p,d,c);
// CREATE A BOOK OBJECT CONTAINING THE INFORMATION READ
// CALL THE ADD METHOD OF THE BESTSELLERS CLASS AND PASS IT THE ABOVE OBJECT
getline(fileIn,t, '\t');
}
do
8
9.
10
« endl;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{ // display the menu of choices
// get the user choice
// perform the proper action
// remember that the cin >> stops at white space and leaves the white space character (including the newline)
// in the input buffer remember that the getline does not skip over white space in the buffer; therefore if you have a
// cin >> followed by a getline, you must use the cin.ignore() after the cin >> to get the newline out of the input buff
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
} while (choice !=3);
42 return 0;
43 }
Transcribed Image Text:1 #include "Book.h" 2 #include "BestSellers.h" 3 #include <fstream> 4 #include <iostream> 5 using namespace std; 6 int main() 7 { BestSellers BestBooks; fstream fileIn("bestsellers.txt",ios::in); if (!fileIn) {cout <« "No open" return 1;} string a,t,p,d,c; int choice=0; getline(fileIn,t,'\t'); // prime read of first title in file while (!fileIn.eof()) { getline(fileIn, a, '\t'); getline(fileIn,p,'\t'); getline(fileIn,d,'\t'); getline(fileIn,c); Book b(t,a,p,d,c); // CREATE A BOOK OBJECT CONTAINING THE INFORMATION READ // CALL THE ADD METHOD OF THE BESTSELLERS CLASS AND PASS IT THE ABOVE OBJECT getline(fileIn,t, '\t'); } do 8 9. 10 « endl; 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 { // display the menu of choices // get the user choice // perform the proper action // remember that the cin >> stops at white space and leaves the white space character (including the newline) // in the input buffer remember that the getline does not skip over white space in the buffer; therefore if you have a // cin >> followed by a getline, you must use the cin.ignore() after the cin >> to get the newline out of the input buff 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 } while (choice !=3); 42 return 0; 43 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY