Thursday, May 24, 2018

CALCULATE MEAN OF TWO NUMBER USING FRIEND FUNCTION IN C++

#include<iostream.h>
#include<conio.h>
class Test
{
 private:
  int a,b;
 public:
  Test(int p,int q)
  {
   a=p;
   b=q;
  }
  void show()
  {
   cout<<"First number="<<a<<endl<<"Second number="<<b<<endl;
  }
  friend float mean(Test x);
};
float mean(Test x)
{
 float s;
 s=(x.a+x.b)/2;
 cout<<"Avg="<<s;
}
void main()
{
 Test ob(12,16);
 clrscr();
 ob.show();
 mean(ob);
 getch();
}

                                              OUTPUT


No comments:

Post a Comment