Write a program in C++ to perform the addition of two numbers using friend function - WAY2IT

Latest Post :

Home Top Ad

Write a program in C++ to perform the addition of two numbers using friend function




Code :-

#include<iostream.h>
#include<conio.h>
class exforsys
{
private:
int a,b;
public:
void test()
{
a=100;
b=200;
}
friend int compute(exforsys e1);
};
int compute(exforsys e1)
{
//Friend Function Definition which has access to private data
return int(e1.a+e1.b)-5;
}
void main()
{
clrscr();
exforsys e;
e.test();
cout<<"The result is:"<<compute(e);
getch(); //Calling of Friend Function with object as argument.
}



Output :-