This is a sample program On using Friend Classes. Using Friend class, here we try to find the mean of two numbers.
#include <iostream.h>
#include <conio.h>
class num
{
int a,b;
public:
void read()
{
cout<<"Enter Two Numbers: ";
cin>>a>>b;
}
friend void mean(num x)
{
int k;
k=(x.a+x.b)/2;
cout<<"Arithmetic Mean: "<<k;
}
};
void main()
{
clrscr();
num n;
n.read();
mean (n);
getch();
}
OUTPUT:
Enter Two Numbers:
18
12
Arithmetic Mean: 15
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com