PROGRAM FOR FRIEND FUNCTION WITH RETURN CLASS

//program for friend function with return class
#include<iostream.h>
#include<conio.h>
class complex
{
  float x,y;
  public:
  void getdata(float r,float i)
  {
    x=r;
    y=i;
  }
  void display()
  {
    cout<<x<<"+i"<<y<<endl;
  }
  friend complex sum(complex,complex);
};
complex sum(complex s1,complex s2)
{
  complex temp;
  temp.x=s1.x+s2.x;
  temp.y=s1.y+s2.y;
  return temp;
}
void main()
{
  complex c1,c2,c3;
  clrscr();
  c1.getdata(1.2,4.3);
  c2.getdata(1.2,9.3);
  c3=sum(c1,c2);
  c1.display();
  c2.display();
  c3.display();
  getch();
}

Comments

Popular Posts