Create class first with data members book no, book name and member function getdata() and putdata(). Create a class second with data members author name, publisher and members getdata() and showdata(). Derive a class third from first and second with data member no of pages and year of publication. Display all these information using array of objects of the third class.




#include<iostream.h>
class first //this is the base class I
{
char name[20];
intbookno;
public:
void getdata()
{

cout<<"\nEnter the name of book : ";
cin>>name;
cout<<"\nEnter Book No. : ";
cin>>bookno;
}
void putdata()
{
cout<<"\nName of Book : "<<name;
cout<<"\nBookNo. :"<<bookno;
}
};
class second //this is the base class II
{
char author[20],publisher[20];
public:
void getdata()
{
cout<<"\nEnter Author's Name : ";
cin>>author;
cout<<"\nEnterPublisher : ";
cin>>publisher;
}
void showdata()
{
cout<<"\nAuthor'sName : "<<author;
cout<<"\nPublisher : "<<publisher;
}
};
class third: public first, public second //this is the derived class
{
intno_pages, year;
public:
void get()
{
first::getdata();
second::getdata();
cout<<"\nEnter No. of Pages : ";
cin>>no_pages;
cout<<"\nEnter the year of publication : ";
cin>>year;
}
void display()
{
putdata();
showdata();
cout<<"\nNo. of Pages : "<<no_pages;
cout<<"\nYear of Publication : "<<year;
}
};
intmain()
{
third book[5];
intnum;
cout<<"\nEnter the number of books : ";
cin>>num;
for(inti=0;i<num;i++)
{
book[i].get();
cout<<endl;
}
for(inti=0;i<num;i++)
{
book[i].display();
cout<<endl;
}
}





The output of the above program is:
Enter the number of books : 1
Enter the name of book : OOPs
Enter Book No. : 128
Enter Author's Name :Sumeet
Enter Publisher : MAIT
Enter No. of Pages : 148
Enter the year of publication : 2005
Name of Book : OOPs
Book No. :128
Author's Name :Sumeet
Publisher : MAIT
No. of Pages : 148
Year of Publication : 2005





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: