Write A Program To Get Mean Value Through Friend Function
#include<iostream>
#include<conio.h>
using namespace std;
class base
{
int val1,val2;
public:
void get()
{
cout<<"Enter two values:";
cin>>val1>>val2;
}
//comments: declaration of friend function ------> friend return_type function_name(argument/s);
friend float mean(base ob);// ob is a object
};
float mean(base ob)//return type function argument
{
return float(ob.val1+ ob.val2)/2;
}
main()
{
// clrscr();
base obj;
obj.get();
cout<<"\n Mean value is : "<<mean(obj);//function call
getch();
}
#include<conio.h>
using namespace std;
class base
{
int val1,val2;
public:
void get()
{
cout<<"Enter two values:";
cin>>val1>>val2;
}
//comments: declaration of friend function ------> friend return_type function_name(argument/s);
friend float mean(base ob);// ob is a object
};
float mean(base ob)//return type function argument
{
return float(ob.val1+ ob.val2)/2;
}
main()
{
// clrscr();
base obj;
obj.get();
cout<<"\n Mean value is : "<<mean(obj);//function call
getch();
}