Search This Blog

Wednesday 24 February 2016

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 )

 Practical 15



#include<iostream>
using namespace std;

class DEF;
class ABC
{
    int a;
    public:
    void getdata()
    {
        cout<<"Enter a number:";
        cin>>a;
    }
    friend void max(ABC,DEF);
};

class DEF
{
    int x;
    public:
    void getdata()
    {
        cout<<"Enter a number:";
        cin>>x;
    }
    friend void max(ABC,DEF);
};
  
void max(ABC p,DEF q)
{
    if(p.a > q.x)
        cout<<p.a<<" is maximum"<<endl;
    else
        cout<<q.x<<" is maximum"<<endl;
}

int main()
{
    ABC m;
    m.getdata();
    DEF n;
    n.getdata();
    max(m,n);
}


output : enter a number
5
enter a number 7

7 is maximum

No comments:

Post a Comment