Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ONLY USE: #include #include #include using namespace std; Write a C++ program that inputs from a file and outputs data to the screen. A base

ONLY USE:

#include

#include

#include

using namespace std;

Write a C++ program that inputs from a file and outputs data to the screen. A base class called book defines the name, type and number of pages in a book. An integer called code is set to 0 for Fiction, 1 for Nonfiction, 2 for Reference. Fiction, Nonfiction and Reference derive from book. Fiction contains a field describing the genre of the Fiction. Nonfiction has two fields: subject and number of illustrations. The data file (books.txt) contains

0 Thunderball 245 Spy

0 Larceny 289 Mystery

1 Airplanes 456 Aviation 250

0 Killer 198 Drama

1 Football 434 Sports 400

1 Lincoln 432 History 307

2 Dictionary 987

2 Atlas 414

producing this output:

Name:Thunderball Type:Fiction Pages:245 Genre:Spy

Name:Larceny Type:Fiction Pages:289 Genre:Mystery

Name:Airplanes Type:Nonfiction Pages:456 Subject:Aviation Illustrations:250

Name:Killer Type:Fiction Pages:198 Genre:Drama

Name:Football Type:Nonfiction Pages:434 Subject:Sports Illustrations:400

Name:Lincoln Type:Nonfiction Pages:432 Subject:History Illustrations:307

Name:Dictionary Type:Reference Pages:987

Name:Atlas Type:Reference Pages:414

Total pages:3455

In main, a single class variable of Book called book is used to store each book of either fiction, nonfiction or reference. Make an enum type for books called Books. Create a BookFactory to construct the required objectand use the enum Books. Use virtual functions to read and print the data. Each class can read only the data declared in it. Each class can print only the data declared in it. A count of the total number of pages of all books in the data is maintained by class book.

Create a PrintAll function for printing books. PrintAll's prototype is

void PrintAll(Book* book);

PrintAll calls the polymorphic Print method of book (the parameter in PrintAll). Remember that each class is responsible for reading and printing its own data. So Fiction, Nonfiction and Reference shouldn't print name, type and the number of pages from Book.

This assignment is about polymorphism, virtual methods, and proper assignment of class responsibility. Each class must read and print its data. MUST FOLLOW THESE INSTRUCTIONS EXACTLY

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_2

Step: 3

blur-text-image_3

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

Students also viewed these Databases questions

Question

Evaluate the integral. x* + 3x? + 1 .2 dx .5 x* + 5x + 5x .3

Answered: 1 week ago

Question

7. Explain why retirees may be valuable as part-time employees.

Answered: 1 week ago

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago