Friday, 26 January 2018

Create two classes ABC and DEF having member data a(int) and x(int) respectively. Create a function MAX that will find the largest value from both class member data. (use friend function)

#include<iostream>
using namespace std;

class def;

class abc
{
    int a;
   
    public:
   
        friend void exchange(abc & ,def & );
       
        void getdata(int z)
        {
            a = z;
        }
};

class def
{
    int x;
   
    public:
       
        friend void exchange(abc & ,def &);
       
        void getdata(int y)
        {
            x = y;
        }
};

void exchange(abc &  obj,def &  obj1)
{
        int temp = obj.a;
        obj.a = obj1.x;
        obj1.x = temp;
       
        cout<<"a(Data member of class abc)is :"<<obj.a;
        cout<<"\nx(Data member of class def)is :"<<obj1.x;
}

int main()
{
    abc ob;
    def ob1;
   
    ob.getdata(11);
    ob1.getdata(1);
   
    exchange(ob,ob1);
    return 0;
}


No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...