Question
create a class called book Book will be a simple class consisting of four fields: name: string representing the name of the book, such as
create a class called book
Book will be a simple class consisting of four fields:
- name: string representing the name of the book, such as Data Structure
- author: string representing the name of the author of the book such as Clifford Shaffer
- publishYear: int representing the year the book has been published such as 2019
- pages: int number of pages of the book such as 234
Your Book class should have the following methods:
- Book(name, author,publishYear,pages) // Constructor
- getName(): string // Returns a Books name
- getAuthor(): String // Returns a Books author
- getPublishYear(): int // Returns a Books publish year
- getPages(): int
The constructor should throw an error if any of the following are true:
- The name is an empty string.
- The author is an empty string
- The publishYear is less than equal to 1900
- The pages is less than equal to zero.
Heres something important to remember: no methods should use standard input or output. They should neither pause to read in input or display any output. While you can include iostream for debugging purposes, your final file that you submit should not include the header.
Create Wrapper Class: Books
Write a wrapper class for a listing of Books. This wrapper class will maintain a list of all Books and will return which Book has the highest number of pages. A wrapper class is a class that acts as decoration for another class (in this case, class vector from the STL). Theres only one field to this class:
- Books: vector of type Book
Your Books should have the following methods:
- addBook(Book): void // Adds a Book to the listing of Books
- getCount(): int // Returns the number of Books currently in this data structure
- getBookWithHighestPages(): Book // Returns the Book with the highest number of pages. If there is a tie among multiple Books, return the Book that was entered first. If the list is empty, throw an error.
- get(int i): Book // Returns the Book which is at position i.
- getNumberOfBooksHavePagesMoreThan(int): int // Counts and returns the number of Books in the data structure that have more pages that the passed parameter.
Like the previous class file, this class should not read in any input or display any output.
Create the Driver Application
Create a driver application that demonstrates that each of the components of your program work. Create an empty Books structure with which to work. Create an interactive menu that gives the user the following choices and then performs that choice:
- Add Book. The program will prompt the user for a name, an author, a publish year, and a number of pages. The program will create that object and pass it to the data structure via a call to addBook.
- Get count. Prints to the screen the number of Books in the data structure.
- Get the Book with the highest number of pages. Prints to the screen the name, author, publish year and pages of the current Book with the highest number of pages in the data structure.
- Quit. Quits the application.
- Get number of Books have the number of pages more than N. Asks the user for an integer and then returns the number of Books have the number of pages more than that integer entered. (Entering a length of 0 should return the count of all Books.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started