//wap in c++ to illustrate the friend function,here we are finding mean of two numbers.

using namespace std;
class sample
int num1,num2;
public :
void setval();
/*here we are passing sample as argument as we are going to pass objects as argument
this is the syntax of Passing Objects as Function Arguments*/
friend float mean(sample);
void sample::setval()
cout<<“Enter two numbers”;
//here we are passing x with sample as we are Passing Object(t) as Function Arguments.
float mean(sample x)
return ((x.num1+x.num2)/2);
int main(){
sample s;
//we can not write mean(s) as s.mean as this is the friend function.

Leave a Reply

Your email address will not be published. Required fields are marked *

To Resolve this issue at just 5$ from ServerExpert


For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat