Using a friend function, find the average of three numbers from three different classes. Write all necessary member functions and constructor for the classes.
CODING:
#include
#include
class C;
class B;
class A
{
int a;
public:
A(int x)
{
a=x;
}
friend void average(A,B,C);
};
class B
{
int b;
public:
B(int y)
{
b=y;
}
friend void average(A,B,C);
};
class C
{
int c;
public:
C(int z)
{
c=z;
}
friend void average(A,B,C);
};
void average(A o1,B o2,C o3)
{
int ans,b=o1.a+o2.b+o3.c;
ans=b/3;
cout<<"AVERAGE :"<>a;
cout<<"Enter the number:"; cin>>b;
cout<<"Enter the number:"; cin>>c;
A ob1(a);
B ob2(b);
C ob3(c);
average(ob1,ob2,ob3);
getch();
}
CODING:
#include
#include
class C;
class B;
class A
{
int a;
public:
A(int x)
{
a=x;
}
friend void average(A,B,C);
};
class B
{
int b;
public:
B(int y)
{
b=y;
}
friend void average(A,B,C);
};
class C
{
int c;
public:
C(int z)
{
c=z;
}
friend void average(A,B,C);
};
void average(A o1,B o2,C o3)
{
int ans,b=o1.a+o2.b+o3.c;
ans=b/3;
cout<<"AVERAGE :"<
cout<<"Enter the number:"; cin>>b;
cout<<"Enter the number:"; cin>>c;
A ob1(a);
B ob2(b);
C ob3(c);
average(ob1,ob2,ob3);
getch();
}
Comments
Post a Comment