Your Ad Here

Sunday, February 10, 2008

Friend Function

/* C++ program for the Implementation Of Friend Function */

#include< iostream.h>
#include< conio.h>
class complex
{
float real;
float imag;
public:
void getdata(float x,float y)
{
real=x;
imag=y;
}
friend complex add (complex c1,complex c2);
void display()
{
cout< < "the complex no is"< < real< < "+i"< < imag< < endl;
}

};
complex add (complex c1,complex c2)
{
complex c3;
c3.real=c1.real+c2.real;
c3.imag=c1.imag+c2.imag;
return (c3);

}
void main()
{
clrscr();
complex c1,c2,c3;

c1.getdata(4.2,5.5);
c2.getdata(3.5,5.6);
c3=add(c1,c2);
c3.display();
}

5 comments:

Your Ad Here