Science, asked by lalipremlama8764, 1 year ago

Write a program to overload binary operator using member function in c++

Answers

Answered by RaviKumarNaharwal
0
#include<conio.h>

#include<iostream.h>

class A

{

int a,b;

public:

void getdata(int p,int q)

{

a=p;

b=q;

}

void display()

{

cout<<“\na=”<<a<<“\nb=”<<b;

}

A operator+(A a1)

{

a1.a=a1.a+a;

a1.b=a1.b+b;

return a1;

}

};

int main()

{

A a1,a2,a3;

int f,g,h,i;

cout<<“\nEnter 2 numbers\n”;

cin>>f>>g;

a1.getdata(f,g);

a1.display();

cout<<“\nEnter 2 numbers\n”;

cin>>h>>i;

a2.getdata(h,i);

a3.display();

a3=a2+a1;

getch();

return 0;

}

Answered by ItzDazzingBoy
0

Answer:

Types of Operator Overloading in C++ ... Overloading binary operator using a friend function. Below are ... C++ program to show unary operator overloading.

Similar questions