PROGRAM TO OVERLOAD BINARY +,-,*,/ OPERATORS

/*PROGRAM TO OVERLOAD BINARY +,-,*,/ OPERATORS*/

#include<conio.h>

#include<iostream.h>

class binry_ovrld

{

int a;

public:

void input()

{

cout<<“enter a: “;

cin>>a;

}

void display()

{

cout<<a<<endl;

}

binry_ovrld operator+(binry_ovrld b2)

{

binry_ovrld temp;

temp.a= a+b2.a;

return (temp);

}

binry_ovrld operator*(binry_ovrld b2)

{

binry_ovrld temp;

temp.a= a*b2.a;

return (temp);

}

binry_ovrld operator/(binry_ovrld b2)

{

binry_ovrld temp;

temp.a= a/b2.a;

return (temp);

}

binry_ovrld operator-(binry_ovrld b2)

{

binry_ovrld temp;

temp.a= a-b2.a;

return (temp);

}

 

};

 

 

void main()

{

binry_ovrld b1,b2,b3;

clrscr();

cout<<“For first object “;

b1.input();

cout<<“For second object “;

b2.input();

cout<<“Value of a for first object: “;

b1.display();

cout<<“Value of a for second object: “;

b2.display();

b3 = b1+b2;

cout<<“Sum of values is: “;

b3.display();

b3 = b1*b2;

cout<<“Multiplication of values is: “;

b3.display();

b3 = b1/b2;

cout<<“Division of values is: “;

b3.display();

b3 = b1-b2;

cout<<“Subtraction of values is: “;

b3.display();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *