Saturday, 23 March 2019

CPP-EX49

Write a C++ program to calculate maximum of two integer numbers of  two different classes using friend function.

#include<iostream.h>
#include<conio.h>
 class Hisclass;
 class Myclass
   {
    public:
    int x;
    Myclass(int a=5):x(a) { }
    ~Myclass() { }
    friend int max(const Myclass &,const Hisclass &);
   };
 class Hisclass
   {
    public:
    int h;
    Hisclass(int a=9):h(a) { }
   
~Hisclass() { }
    friend int max(const Myclass &,const Hisclass &);
   };

 int max(const Myclass &obj1,const Hisclass &obj2)
   {
    return(obj1.x>obj2.h?obj1.x:obj2.h);
   }

int main()
   {
    int a,b;
    clrscr();
    Myclass z;
    Hisclass q;
    cout<<"\nMaximum Number is:"<<max(z,q);
    getch();
    return 0;
   }