Hello Friends!!!! Today I am going to learn about the concept of operator overloading using a simple vector program. In this program we have a class vector and a multiply operator to use and oveload.
So Let's Start=>
//Name : Mayank Sharma //
//Roll No : 1101026 //
//CSE(4th Sem)
PROGRAM TO ILLUSTRATE THE CONCEPT OF OPREATOR OVELOADING
#include
#include
const size=3;
class vector
{
int v[size];
public:
vector();
vector(int *x);
friend vector operator * (int a, vector b);
friend vector operator * (vector b, int a);
friend istream & operator >>(istream &,vector &);
friend ostream & operator <<(ostream &, vector &);
};
vector :: vector()
{
for(int i=0;i
}
vector :: vector(int *x)
{
for(int i=0;i
}
vector operator * (int a,vector b)
{
vector c;
for(int i=0;i
return c;
}
vector operator *(vector b, int a)
{
vector c;
for(int i=0;i
return c;
}
istream & operator >> (istream &din, vector &b)
{
for(int i=0;i
return(din);
}
ostream & operator << (ostream &dout, vector &b)
{
for(int i=0;i
}
int x[size]={2,4,6};
void main()
{
clrscr();
vector m;
vector n=x;
cout<<"Enter Elements of vector m"<<"\n";
cin>>m;
cout<<"\n";
cout<<"m="<
p=2*m;
q=n*2;
cout<<"\n";
cout<<"p="< cout<<"q="< getch();
}
I think this post will help you.I think this post will help you.
Thanks!!!
If any query about this post then put your comment in comment box below..






0 comments:
Post a Comment