Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I require help with the following C++ problem. create a base class named

ID: 3670389 • Letter: H

Question

Hello.

I require help with the following C++ problem.

create a base class named book. Data fields include title and author. Functions include those that can set and display the fields. Derive two classes from the Book class. Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the numbers of pages. 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 sublcass fields. Write a main function that demonstrates the use of the classes and their functions.

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

class Book{
   private:
       string title;
       string author;
   public:
       void setTitle(string t){
           title = t;
           }
       void setAuthor(string a){
           author=a;
           }
       void displayBook(){
           cout<<"Title: "<<title<<", Author: "+author<<endl;
           }
   };
  
   class Fiction: Book{
       private :
           int grade;
       public:
           void setData(string title,string author, int grade){
               setTitle(title);
               setAuthor(author);
               this->grade = grade;
               }
           void display(){
               displayBook();
               cout<<"Grade: "<<grade<<endl;
               }
       };
      
   class NonFiction: Book{
       private :
           int page;
       public:
           void setData(string title,string author, int page){
               setTitle(title);
               setAuthor(author);
               this->page = page;
               }
           void display(){
               displayBook();
               cout<<"Grade: "<<page<<endl;
               }
       };
      
   int main(){
      
       Book b;
       b.setAuthor("Coreman");
       b.setTitle("DS");
       b.displayBook();
      
       Fiction f;
       f.setData("Network","Koronus",23);
       f.display();
       return 0;
       }