Answered step by step
Verified Expert Solution
Question
1 Approved Answer
10.14 LAB: Book information (overriding member functions) Given main() and a base Book class, define a derived class called Encyclopedia with member functions to get
10.14 LAB: Book information (overriding member functions) Given main() and a base Book class, define a derived class called Encyclopedia with member functions to get and set private class data members of the following types: . string to store the edition . int to store the number of pages Within the derived Encyclopedia class, define a PrintInfo() member function that overrides the Book class' Printinfo() function by printing the title, author, publisher, publication date, edition, and number of pages. Ex. If the input is: The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe Ian Ridpath Watson-Guptill 2001 2nd 384the output is: Book Information: Book Title: The Hobbit Author: J. R. R. Tolkien Publisher: George Allen & Unwin Publication Date: 21 September 1937 Book Information : Book Title: The Illustrated Encyclopedia of the Universe Author: Ian Ridpath Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Pages: 384 Note: Indentations use 3 spaces.Current file: Encyclopedia.h Load default template... 1 #ifndef ENCYCLOPEDIAH 2 #define ENCYCLOPEDIAH W 4 #include "Book.h" 5 6 class Encyclopedia : public Book { // TODO: Declare mutator functions - 8 SetEdition(), SetNumPages() 9 10 11 // TODO: Declare accessor functions - 12 GetEdition(), GetNumPages() 13 14 15 // TODO: Declare a PrintInfo() function that overrides 16 the PrintInfo() in Book class 17 18 19 // TODO: Declare private data members 20 21 }; 22 23 #endifCurrent file Encyclopedia.cpp Load default template... 1 #include "Encyclopedia.h" 2 #include 4 // Define functions declared in Encyclopedia. hFile is marked as read only Current file main.cpp 1 #include "Book.h" 2 #include "Encyclopedia.h" 3 #include 4 #include 5 using namespace std; 7 int main() { Book myBook; 9 Encyclopedia myEncyclopedia; 10 11 string title, author, publisher, publicationDate; 12 string eTitle, eAuthor, ePublisher, ePublicationDate, edition; 13 int numPages ; 14 15 getline(cin, title); 16 getline(cin, author); 17 getline(cin, publisher); 18 getline(cin, publicationDate); 19 20 getline(cin, eTitle); 21 getline(cin, eAuthor); 22 getline(cin, ePublisher); 23 getline(cin, ePublicationDate); 24 getline(cin, edition); 25 cin >> numPages ; 26 27 myBook . SetTitle(title); 28 myBook . SetAuthor(author) ; 29 myBook . SetPublisher(publisher); 30 myBook . SetPublicationDate(publicationDate); 31 myBook. PrintInfo();\fFile is marked as read only Current file Book.h - 1 #ifndef BOOKH 2 #define BOOKH 3 4 #include 6 using namespace std; 8 class Book { 9 public: 10 void SetTitle(string userTitle); 11 12 string GetTitle(); 13 14 void SetAuthor(string userAuthor); 15 16 string GetAuthor(); 17 18 void SetPublisher(string userPublisher); 19 20 string GetPublisher(); 21 22 void SetPublicationDate(string userPublicationDate); 23 24 string GetPublicationDate(); 25 26 void PrintInfo(); 27 28 protected: 29 string title; 30 string author; 31 string publisher;\fFile is marked as read only Current file Book.cpp 1 #include "Book.h" #include WN 4 void Book: : SetTitle(string userTitle) { 5 title = userTitle; 6 3 8 string Book: : GetTitle() { 9 return title; 10 3 11 12 void Book: : SetAuthor(string userAuthor) { 13 author = userAuthor; 14 3 15 16 string Book: : GetAuthor() { 17 return author; 18 3 19 20 void Book: : SetPublisher(string userPublisher) { 21 publisher = userPublisher; 22 3 23 24 string Book: : GetPublisher() { 25 return publisher ; 26 3 27 28 void Book: :SetPublicationDate(string userPublicationDate) { 29 publicationDate = userPublicationDate; 30 3 31 32 string Book: : GetPublicationDate() {\f
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