Example of friendly function in c++

Answer Posted / harry0009

#include<iostream.h>
class sample
{
int a,b;
public:
void setvalue()
{
a = 25;
b = 45;
}
friend float mean(sample s);
};
float mean(sample s)
{
return(float(s.a+& b)/20);
}
void main()
{
sample ;
x.setvalue
cout<<"mean value"<<mean(x);
getch();
}

Is This Answer Correct ?    11 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In which language linux is written?

744


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

776


What is non linear data structure in c?

655


Why do some versions of toupper act strangely if given an upper-case letter?

723


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

2000






using for loop sum 2 number of any 4 digit number in c language

1852


How can I sort a linked list?

719


Explain indirection?

740


Write a code of a general series where the next element is the sum of last k terms.

676


What is the function of volatile in c language?

756


Differentiate between null and void pointers.

729


Define circular linked list.

658


How can you find the exact size of a data type in c?

684


How old is c programming language?

679


in iso what are the common technological language?

1721