Question: In C++ 1. Create a base class named Book. Data fields include title, author, and number of pages; functions include a constructor, one that can

In C++

1. Create a base class named Book. Data fields include title, author, and number of pages; functions include a constructor, one that can set all fields, and one that can display the fields, as shown below:

Adventures of Huckleberry Finn by Mark Twain, 336 pages

Derive two classes from the Book class: Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a subject category. For each subclass, include a function that sets all fields, and one that displays all fields. The functions that set and display data field values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code pertaining to the new subclass fields. Write a main() function that demonstrates the use of the classes and their functions.

2. Add an inputData() function to your Book class that will prompt the user for the data and assign the data to the appropriate fields. If the user enters non-numeric data for the number of pages, the function should throw a runtime_error exception. Add an inputData() function to the Fiction and NonFiction classes that overrides the Book class inputData() function. Each of these child class functions should call the Book class inputData() function within a try block, and catch the runtime_error exception if thrown. Then each of these child class functions should have additional statements to prompt the user for the additional info needed for the class. The inputData() function for the Fiction class should also catch non-numeric data entered for reading level.

Write a main function that demonstrates the use of the classes and their functions. The main function should call the inputData() function for a Fiction object and for a NonFiction object within try blocks, and then catch and handle the runtime_error exceptions.

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!