Ad Code

Responsive Advertisement

FInd highest value among three number using friend keywords.






// Find highest value among three number
#include<iostream>
#include<stdlib.h>
using namespace std;
class b1;
class c1;
class a1
{
    int a;
    public:
  void set(int val)
  {
     a=val;
  }
 friend void max(a1,b1,c1);
}s1;

class b1
{
    int b;
    public:
  void set(int val)
  {
      b=val;
  }
 friend void max(a1,b1,c1);
  
}s2;

class c1
{
    int c;
    public:
  void set(int val)
  {
      c=val;
  }
 friend void max(a1,b1,c1);
  
}s3; void max(a1,b1,c1)
{
   if(s1.a>s2.b)
   {
       if(s1.a>s3.c)
       {
           cout<<"a is greater \n";
       }
       else
       {
            cout<<"c is greater \n";
       }
  }
 else
 {
      if(s2.b>s3.c)
      {
           cout<<"b is greater \n";
      }
      else
      {
           if(s3.c>s1.a)
           {
               cout<<" c is greater \n";
           }
           else
           {
                cout<<"a is greater \n"; 
           }
     }
 }
}

int main()
{
     s1.set(30);
     s2.set(40);
     s3.set(35);    max(s1,s2,s3);
}


Out put:
b is greater 

Post a Comment

0 Comments