Computers and Technology

Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a PrintInfo() function that overrides the Book class' PrintInfo() function by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes. Ex. If the input is:
The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe James W. Guthrie Watson-Guptill 2001 2nd 1
the 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: James W. Guthrie Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Volumes: 1
main. cpp:
#include "Book. h"
#include "Encyclopedia. h"
#include
#include
using namespace std;
int main(int argc, char* argv[]) {
Book myBook;
Encyclopedia myEncyclopedia;
string title, author, publisher, publicationDate;
string eTitle, eAuthor, ePublisher, ePublicationDate, edition;
int numVolumes;
getline(cin, title);
getline(cin, author);
getline(cin, publisher);
getline(cin, publicationDate);
getline(cin, eTitle);
getline(cin, eAuthor);
getline(cin, ePublisher);
getline(cin, ePublicationDate);
getline(cin, edition);
cin >> numVolumes;
myBook. SetTitle(title);
myBook. SetAuthor(author);
myBook. SetPublisher(publisher);
myBook. SetPublicationDate(publicationDate) ;
myBook. PrintInfo();
myEncyclopedia. SetTitle(eTitle);
myEncyclopedia. SetAuthor(eAuthor);
myEncyclopedia. SetPublisher(ePublisher);
myEncyclopedia. SetPublicationDate(ePublicationDate );
myEncyclopedia. SetEdition(edition);
myEncyclopedia. SetNumVolumes(numVolumes);
myEncyclopedia. PrintInfo();
return 0;
}
Book. h:
#ifndef BOOKH
#define BOOKH
#include
using namespace std;
class Book {
public:
void SetTitle(string userTitle);
string GetTitle();
void SetAuthor(string userAuthor);
string GetAuthor();
void SetPublisher(string userPublisher);
string GetPublisher();
void SetPublicationDate(string userPublicationDate);
string GetPublicationDate();
void PrintInfo();
protected:
string title;
string author;
string publisher;
string publicationDate;
};
#endif
Book. cpp:
#include "Book. h"
#include
void Book::SetTitle(string userTitle) {
title = userTitle;
}
string Book::GetTitle() {
return title;
}
void Book::SetAuthor(string userAuthor) {
author = userAuthor;
}
string Book::GetAuthor() {
return author;
}
void Book::SetPublisher(string userPublisher) {
publisher = userPublisher;
}
string Book::GetPublisher() {
return publisher;
}
void Book::SetPublicationDate(string userPublicationDate) {
publicationDate = userPublicationDate;}
string Book::GetPublicationDate() {
return publicationDate;
}
void Book::PrintInfo() {
cout << "Book Information: " << endl;
cout << " Book Title: " << title << endl;
cout << " Author: " << author << endl;
cout << " Publisher: " << publisher << endl;
cout << " Publication Date: " << publicationDate << endl;
}
Encyclopedia. h:
#ifndef ENCYCLOPEDIAH
#define ENCYCLOPEDIAH
#include "Book. h"
class Encyclopedia : public Book {
// TODO: Declare mutator functions -
// SetEdition(), SetNumVolumes()
// TODO: Declare accessor functions -
// GetEdition(), GetNumVolumes()
// TODO: Declare a PrintInfo() function that overrides
// the PrintInfo in Book class
// TODO: Declare private fields: edition, numVolumes
};
#endif
Encyclopedia. cpp:
#include "Encyclopedia. h"
#include
// Define functions declared in Encyclopedia. h

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 13:30, samanthalopez11
To remove a header or footer from a document you can open the header and footer and manually delete the content true or false
Answers: 1
image
Computers and Technology, 22.06.2019 04:30, ParallelUniverse
Which of the statements below is true? the formatting, standard, and drawing commands are unavailable. the formatting, standard, and drawing commands have been used. the formatting, standard, and drawing toolbars are displayed. the formatting, standard, and drawing toolbars are hidden.
Answers: 1
image
Computers and Technology, 22.06.2019 09:40, vanessacasillas452
In the lab, which of the following displayed a list of all installed services and included a description of the service, the current state, and whether the service started automatically or manually? a. the services manager b. the applications summary c. the recommended services d. list the safe services list
Answers: 2
image
Computers and Technology, 22.06.2019 13:10, LuckyCharms988
Calculating the "total price" of an item is tedious, so implement a get_item_cost method that just returns the quantity times the price for an item. by the way, the technical term for this kind of instance method is an accessor method, but you'll hear developers calling them getters because they always start with "get" and they get some value from instance attributes. in order to make the items sortable by their total total price, we need to customize our class. search the lectures slides for "magic" to see how to do this. see section 9.8 for an additional reference. the receipt class: this will be the class that defines our receipt type. obviously, a receipt will consist of the items on the receipt. this is called the composition design pattern. and it is very powerful. instance attributes: customer_name : it is very important to always know everything you can about your customers for "analytics", so you will keep track of a string customer name in objects of type receipt. date : the legal team has required that you keep track of the dates that purchases happen for "legal reasons", so you will also keep track of the string date in objects of type receipt. cart_items : this will be a list of the items in the cart and hence end up on the receipt. methods: 1. create a default constructor that can take a customer name as an argument, but if it gets no customer name, it will just put "real human" for the customer_name attribute. it should also accept a date argument, but will just use the value "today" for the date instance attribute if no date is given. the parameters should be named the same as the instance attributes to keep things simple. 2. add_item : self-descriptive. takes a parameter which we hope beyond hope is of type itemtopurchase and adds it to the cart_items. returns none. 3. print_receipt : takes a single parameter isevil, with default value true. returns a total cost of all the items on the receipt (remember to factor in the quantity). prints the receipt based on the following specification: for example, if isevil is true, and customer_name and date are the default values: welcome to evilmart, real human today have an evil day! otherwise, it should print: welcome to goodgo, real human today have an good day! then the receipt should be printed in sorted order like we discussed earlier, but whether or not it starts with the highest cost (think reverse), depends on the value of isevil. if it is evil, then the lowest cost items should print first, but if it is good, then it will print the highest cost items first. (cost meaning price*quantity). remember to return the total cost regardless! your main() function: the main flow of control of your program should go in a main() function or the program will fail all the unit tests. get the name of the customer with the prompt: enter customer name: get the date with the prompt: enter today's date then, ask the question: are you evil? your program should consider the following as true: yeah yup let's face it: yes hint: what do these strings all have in common? your program should consider all the following as false: no nah perhaps but i'm leaning no (just be glad you don't have to handle "yeah no.") okay enough horsing around. (get it? aggies? ! horsing! ) next, in the main() function, you will have to create a receipt object and start adding things into it using an input-while loop. the loop will prompt the user for the item name exactly as in the previous zylab (9.11). but unlike the previous zylab, the loop will terminate only if an empty string is entered for the item name. then, the price and the quantity will be prompted for exactly as in the previous zylab. create the itemtopurchase objects in the same manner as the previous zylab, but don't forget to add them to the receipt using your add_item instance method. then, the items on the receipt should be printed with the same formatting as in the previous zylab, of course with either "good" or "evil" ordering. however, on the last line, the total should be printed as follows: where 10 is replaced by the actual total. sample run here is what a sample run of the final program should look like: enter customer name: nate enter today's date: 12/20/2019 are you evil? bwahahahaha yes enter the item name: bottled student tears enter the item price: 2 enter the item quantity: 299 enter the item name: salt enter the item price: 2 enter the item quantity: 1 enter the item name: welcome to evilmart, nate 12/20/2019 have an evil day! salt 1 @ $2 = $2 bottled student tears 299 @ $2 = $598 total: $600
Answers: 1
Do you know the correct answer?
Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived E...

Questions in other subjects:

Konu
Mathematics, 12.02.2021 16:20
Konu
History, 12.02.2021 16:20
Konu
Mathematics, 12.02.2021 16:20