source file name: friend3.cpp

 #include<conio.h>

#include<iostream.h>

class Average

{

int x,y,z;

public:

void setnos(int a, int b,int c)

{

x=a;

y=b;

z=c;

}

friend float avg(Average a);

};

float avg(Average ob)

{

float r=(ob.x+ob.y+ob.z)/3;

return r;

}

void main()

{

clrscr();

cout<<"Program on Friend Function: "<<endl;

Average ob1;

ob1.setnos(11,202,35);

cout<<" average value is  : "<< avg(ob1);

getch();

}

output:


Program on Friend Function:

average value is  : 82