Finding Greatest Between Data Member Of One Class And Another Class

Finding greatest between data member of one class and another class by making the member function of one class as a friend function of another class.






Finding greatest between data member of one class and another class by making the member function of one class as a friend function of another class.

#include<iostream.h>
#include<conio.h>
class second;  // Forward declaration to satisfy the compiler about class B
class first
{    int a ;
     void get()
     { cout<<"enter the value of a:";
       cin>>a;
     }
     public: void greatest(second);
};
class second
{
    int b ;
    void get()
    { cout<<"enter the value of b:";
      cin>>b;
    }
    friend  void first:: greatest(second);
};
void first::greatest (second ob2 )
{  get();
   ob2.get();
   if(a>ob2.b)
     cout<<"greatest is"<<a ;
   else
   cout<<"greatest is:"<<ob2.b;
}
void main()
{
 clrscr();
 first ob1;
 second ob2;
 ob1.greatest(ob2) ;
 getch();
}

Labels: