Wednesday, April 7, 2021

simple program using inheritance (OOP) (59)

#include<iostream>

using namespace std;

class Book //here i make a first class name book

{

protected:

string author_name,isbn,title;

int number_of_pages;

float price;

public:

Book()  //here i define a default constructure

{

author_name="";

isbn="";

title="";

number_of_pages=0;

price=0;

}

Book(string x,string y,float z)  //here i define a first parameterized constructure

{

author_name=x;

title=y;

price=z;

}

Book(string x,string y,float z,int n,string i) // //here i define a second parameterized constructure

{

author_name=x;

title=y;

price=z ;

number_of_pages=n;

isbn=i;

}

void displayB()

{

cout<<"author name is:"<< author_name<<endl;

cout<<"book title is:"<<title<<endl;

cout<<"book price is:"<<price<<endl;

cout<<"number of pages in a book are:"<<number_of_pages<<endl;

cout<<"isbn is:"<<isbn<<endl;

}

};

class EBook:public Book //here i make a second class name Ebook inherit with Book class

{

private:

string download_url;

float sizeMb;

public:

EBook() //here i define a default constructure

{

download_url="";

sizeMb=0;

}

EBook(string x,string y,float z,float s) //here i define a first parameterized constructure

{

author_name=x;

title=y;

price=z;

sizeMb=s;

}

EBook(string x,string y,float z,int n,string i,float s,string d) //here i define a second parameterized constructure

{

author_name=x;

title=y;

price=z;

download_url=d;

sizeMb=s;

number_of_pages=n;

isbn=i;

}

void displayeB()

{

cout<<"author name is:"<< author_name<<endl;

cout<<"book title is:"<<title<<endl;

cout<<"book price is:"<<price<<endl;

cout<<"number of pages in a book are:"<<number_of_pages<<endl;

cout<<"isbn is:"<<isbn<<endl;

cout<<"size is:"<<sizeMb<<endl;

cout<<"downlod url:"<< download_url<<endl;

}

};

class paperBook:public Book  //here i make a third class name paperbook inherit with Book class

{

private:

int number_of_copies;

float weight;

public:

paperBook() //here i define a default constructure

{

number_of_copies=0;

weight=0;

}

paperBook(string x,string y,float z,int nc) //here i define a first parameterized constructure

{

author_name=x;

title=y;

price=z;

number_of_copies=nc;

}

paperBook(string x,string y,float z,int n,string i,int nc,float w) //here i define a second parameterized constructure

{

author_name=x;

number_of_pages=n;

title=y;

price=z;

isbn=i;

number_of_copies=nc;

weight=w;

}

void displaypB()

{

cout<<"author name is:"<< author_name<<endl;

cout<<"book title is:"<<title<<endl;

cout<<"book price is:"<<price<<endl;

cout<<"number of pages in a book are:"<<number_of_pages<<endl;

cout<<"isbn is:"<<isbn<<endl;

cout<<"number of copies are:"<<number_of_copies<<endl;

cout<<"weight is:"<<weight<<endl;

}

};

class audioBook:public Book  //here i make a fourth class name audiobook inherit with Book class

{

private:

int playing_time;

public:

audioBook() //here i define a default constructure

{

playing_time=0;

}

audioBook(string x,string y,float z,int pt) //here i define a first parameterized constructure

{

playing_time=pt;

title=y;

price=z;

author_name=x; 

}

audioBook(string x,string y,float z,int n,string i,int pt) //here i define a second parameterized constructure

{

playing_time=pt;

author_name=x;

number_of_pages=n;

title=y;

price=z;

isbn=i;

}

void displayaB()

{

cout<<"author name is:"<< author_name<<endl;

cout<<"book title is:"<<title<<endl;

cout<<"book price is:"<<price<<endl;

cout<<"number of pages in a book are:"<<number_of_pages<<endl;

cout<<"isbn is:"<<isbn<<endl;

cout<<"playing time is:"<< playing_time<<endl;

}

};

int main()

{

Book obj1(); //this object is used for default constructor

Book obj2("Hamza","c++",1300); //this object is used for second  constructor

Book obj3("Hamza","c++",1300,450,"8293"); //this object is used for third constructor

obj3.displayB();

EBook obj4(); //this object is used for default constructor

EBook obj5("Hamza","c++",1300,3); //this object is used for second  constructor

EBook obj6("Hamza","c++",1300,450,"8293",3.5,"hdjdjf"); //this object is used for third constructor

obj6.displayeB();

paperBook obj7(); //this object is used for default constructor

paperBook obj8("Hamza","c++",1300,700); //this object is used for second  constructor

paperBook obj9("Hamza","c++",1300,450,"74845",700,12.2); //this object is used for third constructor

obj9.displaypB();

audioBook obj10(); //this object is used for default constructor

audioBook obj11("Hamza","c++",1300,5); //this object is used for second  constructor

audioBook obj12("Hamza","c++",1300,450,"76887",5); //this object is used for third constructor

} 

No comments:

Post a Comment