.
Home About-us Privacy Policy Contact-us Services

Friday, October 9, 2015

C++ Program to use the virtual function

ad+1

Program -


#include<iostream.h>
#include<conio.h>
#include<math.h>
class abc
{
public:
int a,b;
void read()
{
cout<<"enter the integer values";
cin>>a>>b;
}
virtual void display()
{
cout<<"this is base class abc;"<<endl;
}
};
class xyz:public abc
{
private:
int c,r;
public:
void display()
{
abc::read();
c=a+b;
cout<<"the sum is="<<c<<endl;
}
};
class lmn:public abc
{
private:
int d;
public :
void display()
{
abc::read();
d=a*b;
cout<<"the multiplaction is="<<d;
}
};
void main()
{
clrscr();
class abc*p;
class xyz m;
cout<<"base class xyz:"<<endl;
p=&m;
p->display();
cout<<"\n base class lmn\n ";
class lmn r;
p=&r;
p->display();
getch();
}

Output - 
base class xyz:
enter the integer values 9 8
the sum is=17

base class lmn
enter the integer values7 5
the multiplaction is=35

 

 


0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates