Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ A Publishing House publishes stories in three categories and has strict requirements for page counts in each one. Create an abstract class called Story

C++

A Publishing House publishes stories in three categories and has strict requirements for page counts in each one. Create an abstract class called Story, which has the following data members: story title (title), author name (author), number of pages (pages), type of story book (type), and a string message (msg). Include get and set member functions for each field. Follow the naming convention for the setter and getter functions for each data member, such as setTilte(), getTitle(), etc. The Story abstract class has a constructor that accepts the type of story book as a parameter to initialize its type field. The type of story books considered are Novel, Novella and Short Story. The function that sets the number of pages (setPages()) is abstract. The setPages() function accepts one parameter for the number of words per page.

Create three Story subclasses called Novel, Novella, and ShortStory. The three child classes represent three types of stories, each with a specific page requirement. Each subclass has extra data members as constants for the page lower and upper limits in that category, and an extra data member for the number of words in the book. For the Novelsubclass, the lower limit of pages is 101. For the Novella subclass, the lower limit is 51 pages and the upper limit is 100. For the ShortStory, the lower limit is 5 and the upper limit is 50 pages. Include a constructor for each subclass that may be passed two parameters for initializing the number of words in the book and the type of story book; and include get and set member functions for the subclass data member. The setPages() member function should compute the possible number of pages in the book based on the number of words and the number of words per page passed as a parameter. The function should check whether the candidate book needs to be cut by a certain number of pages, or added certain number of pages to qualify for the type of story requirement. Otherwise, the book would be accepted. Accordingly, the function sets the msg data member with the required message to be used for display. See the example below for the format and contents of the messages.

Implement each class in a separate header file that carries the class's name, such as: "Story.h", "Novel.h", etc.

Vocareum Automatic Grading

  • Upload your class implementation files to Vocareum.
  • The driver program "RA9prog.cpp" will be used to test your implementations. The program reads book information from a file and displays the list of candidate books along with possible messages to adjust the book to the book category requirement. An example of the expected output is shown in the slides.

prog file that provided:

#include #include #include #include #include #include

#include "Story.h" #include "Novel.h" #include "Novella.h" #include "ShortStory.h"

using namespace std;

int main(int argc, char *argv []) {

ifstream file; vector< Story * > StoryList; vector< Story * >::iterator listitr; Novel *novelbook; Novella *novellabook; ShortStory *shortbook; string strline, title, author, msg, storytype; int words, type, wordsperpage; if( argc >= 2 ) { file.open(argv[1]); if( !file) { /* error */ cerr << "File cannot be opened: " << argv[1] << endl; exit (1); } } else { cerr << "No file is found." << endl; exit (1); } while (file >> type >> words >> wordsperpage ) { file.ignore(); getline(file, title, ','); getline(file, author, ' '); if(type == 1) { //Novel novelbook = new Novel("Novel", words); novelbook->setTitle(title); novelbook->setAuthor(author); //novelbook->setWords(words); novelbook->setPages(wordsperpage); StoryList.push_back(novelbook); } else if(type == 2) { //Novella novellabook = new Novella("Novella"); novellabook->setTitle(title); novellabook->setAuthor(author); novellabook->setWords(words); novellabook->setPages(wordsperpage); StoryList.push_back(novellabook); } else { //ShortStory shortbook = new ShortStory("Short Story", words); shortbook->setTitle(title); shortbook->setAuthor(author); //shortbook->setWords(words); shortbook->setPages(wordsperpage); StoryList.push_back(shortbook); } } cout << "List of candidate story books to be published:" << endl ; for ( int i = 0; i < StoryList.size(); i++ ) { title = (*StoryList[i]).getTitle(); cout<< i+1 << ". " << "Title: " << title <

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions