HOME

Sunday, November 29, 2015

FRIEND FUCNTION TO FIND GREATER NUMBER

#include<iostream>
using namespace std;
class XYZ;
class ABC
{
    int x;
public:
    void getx()
    {
        cout<<"ENTER VALUE OF X"<<endl;
        cin>>x;
    }
    friend void greaterr(ABC,XYZ);
};
class XYZ
{
    int y;
public:
    void gety()
    {
        cout<<"ENTER VALUE OF Y "<<endl;
        cin>>y;
    }
    friend void greaterr(ABC,XYZ);
};
void greaterr(ABC obj1, XYZ obj2)
{
    if(obj1.x>obj2.y)
    {
        cout<<"X is greater"<<endl;
    }
    else
    {
        cout<<"Y is greater"<<endl;
    }
}
int main()
{
    ABC obj1;
    XYZ obj2;
    obj1.getx();
    obj2.gety();
    greaterr(obj1,obj2);
    return 0;
}

No comments:

Post a Comment