Monday 28 April 2014

binary operator overloading


#include<conio.h>
#include<iostream>
using namespace std;
class multi
{
float a,b;
public:
multi(){a=0; b=0;}
void get()
{
cout<<"\n enter the value of a and b";
cin>>a>>b;
}
void show()
{
cout<<"\n value of a= "<<a<<endl;
cout<<" value of b= "<<b<<endl;
}
multi operator*(multi &m)
{
multi temp;
temp.a=this->a*m.a;
temp.b=this->b*m.b;
return temp;
}

};
int main()
{
multi b1,b2,b3;
cout<<"\nfirst object";
b1.get();
cout<<"\nsecond object";
b2.get();
cout<<"\nthird object :after multiplication of first and second object";
b3=b1*b2;
b3.show();
getch();
return 0;
}

No comments:

Post a Comment