Create a class ‘Book’. Derive two classes from it namely ‘’Print_Book’ and
‘E_Book’. Store the following details about the book in the relevant classes.
Title, Author, Price, No of pages and Size in KB.
Input information for ‘m’ number of print books and ‘n’ number of eBooks and
display it.
#include<iostream>
using namespace std;
class Book{
//Title, Author, Price, No of pages and Size in KB.
};
class Print_Book: Book{
private:
string Title, Author;
int price, No_of_pages;
public:
void setPrint_Book(string t, string a, int p, int n){
Title = t;
Author = a;
price = p;
No_of_pages = n;
}
void displayPrint_Book(){
cout<<"Title: "<<Title<<"\nAuthor: "<<Author<<"\nPrice: "<<price<<"\nNo of pages: "<<No_of_pages<<endl;
}
};
class E_Book: Book{
private:
string Title, Author;
int price, No_of_pages, size_in_kb;
public:
void setE_Book(string t, string a, int p, int n, int s){
Title = t;
Author = a;
price = p;
No_of_pages = n;
size_in_kb = s;
}
void displayE_Book(){
cout<<"Title: "<<Title<<"\nAuthor: "<<Author<<"\nPrice: "<<price<<"\nNo of pages: "<<No_of_pages<<endl;
cout<<"Size in KB: "<<size_in_kb<<endl;
}
};
int main(){
cout<<"Enter the total number of print books\n";
int m;
cin>>m;
cout<<"Enter the total number of eBooks\n";
int n;
cin>>n;
Print_Book pBook[m];
E_Book eBook[n];
cout<<"Enter details of the print books:\n";
for(int i=0; i<m; i++){
cout<<"Book: "<<(i+1)<<endl;
string Title, Author;
int price, No_of_pages;
cout<<"Enter the title: \n";
cin>>Title;
cout<<"Enter the Author:\n";
cin>>Author;
cout<<"Enter the Price:\n";
cin>>price;
cout<<"Enter the No of pages:\n";
cin>>No_of_pages;
pBook[i].setPrint_Book(Title, Author, price, No_of_pages);
}
cout<<"Enter details of the ebooks:\n";
for(int i=0; i<n; i++){
cout<<"Book: "<<(i+1)<<endl;
string Title, Author;
int price, No_of_pages, size_in_kb;
cout<<"Enter the title: \n";
cin>>Title;
cout<<"Enter the Author:\n";
cin>>Author;
cout<<"Enter the Price:\n";
cin>>price;
cout<<"Enter the No of pages:\n";
cin>>No_of_pages;
cout<<"Enter the size in kb:\n";
cin>>size_in_kb;
eBook[i].setE_Book(Title, Author, price, No_of_pages, size_in_kb);
}
cout<<"\nDetails of Print Books:\n";
for(int i=0; i<m; i++){
cout<<"Book: "<<(i+1)<<endl;
pBook[i].displayPrint_Book();
}
cout<<"\nDetails of eBooks:\n";
for(int i=0; i<n; i++){
cout<<"Book: "<<(i+1)<<endl;
eBook[i].displayE_Book();
}
}
Comments
Leave a comment