Thursday, 28 April 2016

Write a program showing Friend Function

 #include<iostream.h>
 #include<conio.h>
 class b;
 class a
 {
int no1;
public:
void accept()
{
cout<<"Enter no 1:";
cin>>no1;
}
void display()
{
cout<<"No 1 is greater";
}
friend void great(a,b);
 };
 class b
 {
int no2;
public:
void accept()
{
cout<<"Enter no 2:";
cin>>no2;
}
void display()
{
cout<<"No 2 is greater";
}
friend void great(a,b);
 };
 void great(a m,b n)
 {
if(m.no1>n.no2)
{
m.display();
}
else
{
n.display();
}
 }
 void main()
 {
clrscr();
a m;
b n;
m.accept();
n.accept();
great(m,n);
getch();
}
/*Output:
Enter no 1:23
Enter no 2:21                                                                  
No 1 is greater */

No comments:

Post a Comment