Question
I need help adding the following to my C++ code Add the following functions to the Book class code: A constructor method with no parameters.
I need help adding the following to my C++ code
Add the following functions to the Book class code:
- A constructor method with no parameters. It should set title to "TBA", author to "Anonymous", price to 0, and publication year to 2019
- A second constructor method with parameters that sets the book member variables with initial values
- A class method with four parameters that will set the member variables. It behaves exactly like the constructor above
- A destructor method that simply outputs "Book is destroyed"
- A class method that will update the price of a book. It will have one parameter, a discount rate, that simply is multiplied by the price. If the rate is 0.9 for example, the new book price would be 90% of what it was before. A rate of 1.25 would raise the book price by 25%.
- A function outside of the class definition that will read data from a text file into an array of Book objects by calling the set book method described above. It should also update a count of the number of books that were actually read in from the file. The file should be named "books.txt" and should have 3 lines (1st line title, 2nd line author, 3rd line price and year separated by a space) for each book. Assume the data file will contain a maximum of 10 books.
- A function outside of the class definition that will print all of the books. It should loop through all of the books by making a call to the object's print method.
- Modify the main driver function so that it calls the functions to read all of the book objects and then print them all to the screen. Make a call to the update price method and include necessary print statements to indicate that it worked.
The Code to add to:
#include
void bookInformation::setPrice(double pri) { price= pri; }
void bookInformation::setTitle(string titl) { title=titl; }
void bookInformation::setAuthor(string aut) { author= aut; } void bookInformation::setPublication(int pub) { publication= pub; } double bookInformation::getPrice() const { return price; }
string bookInformation::getTitle() const { return title; }
string bookInformation::getAuthor() const { return author; }
int bookInformation::getPublication() const { return publication; }
void bookInformation:: print() const { cout << "Book Title: " << title << endl; cout << "Author: " << author << endl; cout << "Price: $" << price << endl; cout << "Publication Year: " << publication << endl; }
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