Using a friend function, find the average of three numbers from three different classes.
Write all necessary member functions and constructor for the classes.
#include<iostream>
using namespace std;
class xyz;
class pqr;
class abc
{
int a;
public:
abc(int a1)
{
a=a1;
}
void printa()
{
cout<<a<<endl;
}
friend void avg(abc,xyz,pqr);
};
class xyz
{
int x;
public:
xyz(int x1)
{
x=x1;
}
void printx()
{
cout<<x<<endl;
}
friend void avg(abc,xyz,pqr);
};
class pqr
{
int p;
public:
pqr(int p1)
{
p=p1;
}
void printp()
{
cout<<p<<endl;
}
friend void avg(abc,xyz,pqr);
};
void avg(abc obj1,xyz obj2,pqr obj3)
{
int avg=(obj1.a+obj2.x+obj3.p)/3;
cout<<"\n Avarage is"<<avg;
}
void main()
{
abc o1(10);
xyz o2(20);
pqr o3(30);
o1.printa();
o2.printx();
o3.printp();
avg(o1,o2,o3);
}