Question
Exercise 1: Run your driver for class LibBook put pass an object of class Book as a parameter to function Print. Describe what happened. ?If
Exercise 1: Run your driver for class LibBook put pass an object of class Book as a parameter to function Print. Describe what happened. ?If the output for exercise 1 is what you would expect, good if not do you know what you would have to do to make it work properly? Describe what must be done.
#include
#include
#include
using namespace std;
class Book
{
private:
string title;
string author;
string ISBN;
public:
Book(string tit="",string aut="",string isbn="") {
title = tit;
author = aut;
ISBN = isbn;
}
void PrintBook()
{
cout << title << setfill ('-')<< setw (30) << author << setfill ('-')<< setw (30) << ISBN << setfill ('-')<< setw (30) ;
}
void setTitle(string tit)
{
title = tit;
}
void setAuthor(string aut)
{
author = aut;
}
void setISBN(string isbn)
{
ISBN = isbn;
}
};
class LibBook:public Book {
private:
string ddc;
public:
LibBook(string title,string author,string isbn,string ddc):Book(title,author,isbn)
{
this->ddc =ddc;
}
void setDdc(string ddc)
{
this->ddc =ddc;
}
void PrintBook()
{
static_cast
cout << ddc << setfill ('-') << endl;
}
};
void Print(Book book)
{
cout << "Title" << setfill ('-')<< setw (30) << "Author" << setfill ('-')<< setw (30) << "ISBN" << setfill ('-')<< setw (30) < book.PrintBook(); } void Print(LibBook book) { cout << "Title" << setfill ('-')<< setw (30) << "Author" << setfill ('-')<< setw (30) << "ISBN" << setfill ('-')<< setw (30) << "ddc" << setfill ('-') << endl; book.PrintBook(); } int main() { string title, author, isbn, ddc; // cin >> title >> author >> isbn >> ddc; cout <<"Enter Book Title name :"; getline(cin,title); cout <<"Enter Book Author name :"; getline(cin,author); cout <<"Enter Book ISBN :"; getline(cin,isbn); cout <<"Enter Book ddc :"; getline(cin,ddc); LibBook b(title, author, isbn, ddc); Print(b); system("pause"); return 0; }
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