Write a C++ program demonstrating use of the pure virtual function with the use of base and derived classes.
Code :
#include<iostream.h>
#include<conio.h>
class base
{
public:
int a;
virtual void show()=0;
};
class derived : public base
{
int b;
void show()
{
cout<<"Enter A : ";
cin>>a;
cout<<"Enter B : ";
cin>>b;
cout<<"\nSimple Addtion : "<<a+b;
}
};
void main()
{
clrscr();
cout<<"Program demonstrates the use of Pure Virtual Function.\n";
base *z=new derived();
z->show();
getch();
}
Output :
No comments:
Post a Comment