Thursday, January 31, 2013

ADDITION OF TWO NUMBERS IN C++ USING FRIEND FUNCTION

/* FRIEND FUNCTION DEMO */


#include<iostream.h>
#include<conio.h>

class two;
class one
{
private:int data1;
public: void setdata(int init)
{
data1=init;
}
friend int add_both(one a,two b);

};//class

class two
{
private: int data2;
public:
void setdata(int init)
{
data2=init;
}
friend int add_both(one a,two b);
};
int add_both(one a,two b)
{
return a.data1+b.data2;
}
void main()
{
one a;
two b;

int i,j;
clrscr();
cout<<"Enter the value of a & b";
cin>>i>>j;

a.setdata(i);
b.setdata(j);
cout<<"sum of one & two :"<<add_both(a,b);
getch();
}