VIRTUAL FUNCTION USING C++
/*BOOK DETAILS USING VIRTUAL FUNCTION */
PROGRAM:
#include<iostream.h>
#include<conio.h>
class author
{
char aname[20],acon[20];
long int phn;
public:
virtual void getdata();
virtual void display();
}a[10];
class book:public author
{
char bname[20],pub[20];
char date[10],ed[10];
public:
void getdata();
void display();
}b[10];
void author::getdata()
{
cout<<"\n\t\t AUTHOR DETAILS";
cout<<"\n Enter the author name:";
cin>>aname;
cout<<"\n enter the author country:";
cin>>acon;
cout<<"\n Enter the author phone no:";
cin>>phn;
}
void author::display()
{
cout<<"\n Author name :"<<aname;
cout<<"\n Author country:"<<acon;
cout<<"\n Author phoneno:"<<phn;
}
void book::getdata()
{
cout<<"\n\t\t BOOK DETAILS ";
cout<<"\n Enter the book name:";
cin>>bname;
cout<<"\n Enter the book publish date:";
cin>>date;
cout<<"\n Enter the edition:";
cin>>ed;
cout<<"\n Enter the publisher name:";
cin>>pub;
}
void book::display()
{
cout<<"\n Book name:"<<bname;
cout<<"\n Publish date:"<<date;
cout<<"\n edition:"<<ed;
cout<<"\n Publisher name:"<<pub;
}
void main()
{
int n,i;
author *ab[10],*bb[10];
clrscr();
cout<<"\n\t\t BOOK DETAILS USING VIRTUAL FUNCTION ";
cout<<"\n Enter the no of books:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<i+1<<"Book";
ab[i]=&a[i];
bb[i]=&b[i];
ab[i]->getdata();
bb[i]->getdata();
}
cout<<i+1<<"Details";
ab[i]=&a[i];
bb[i]=&b[i];
ab[i]->display();
bb[i]->display();
getch();
}
OUTPUT:
BOOK DETAILS USING VIRTUAL FUNCTION
Enter the no of books:2
1Book
AUTHOR DETAILS
Enter the author name: Michele E. Davis
enter the author country:usa
Enter the author phone no:12456
BOOK DETAILS
Enter the book name:Learning PHP5 and MySQL
Enter the book publish date:2000
Enter the edition:3th
Enter the publisher name:O’Reilly
2Book
AUTHOR DETAILS
Enter the author name:kamthane
Enter the author country:kanada
Enter the author phone no:63689
BOOK DETAILS
Enter the book name:c++
Enter the book publish date:1890
Enter the edition:4th
Enter the publisher name:mcgrouhill
Comments
Post a Comment