PROGRAM FOR FRIEND FUNCTION USING CALL BY REFERENCE

//program for friend function using call by reference
#include<iostream.h>
#include<conio.h>
class class_2;
class class_1
{
  int value1;
  public:
void in(int a)
{
 value1=a;
}
void display(){cout<<value1<<endl;}
friend void exchange(class_1 &,class_2 &);
};
class class_2
{
  int value2;
  public:
void in(int a)
{
 value2=a;
}
void display(){cout<<value2<<endl;}
friend void exchange(class_1 &,class_2 &);
};
void exchange(class_1 &c1,class_2 &c2)
{
  int temp=c1.value1;
  c1.value1=c2.value2;
  c2.value2=temp;
}
void main()
{
   class_1 C1;
   class_2 C2;
   clrscr();
   C1.in(100);
   C2.in(200);
   cout<<"value for exchange:"<<endl;
   C1.display();
   C2.display();
   exchange(C1,C2);
    cout<<"value after exchange:"<<endl;
   C1.display();
   C2.display();
   getch();
}

Comments

Popular Posts