WAP to create 3 Classes. Each class must have input function (to input one value from user) and display function. Make a common friend function of three class that find greatest number.
#include <iostream>
using namespace std;
class A;
class B;
class C;
class A{
 int member;
 public:
 A(int x): member(x){}
 int getMember(){
  return member;
 }
 friend int findMax(A a, B b, C c);
};
class B{
 int member;
 public:
 B(int x): member(x){}
 int getMember(){
  return member;
 }
 friend int findMax(A a, B b, C c);
};
class C{
 int member;
 public:
 C(int x): member(x){}
 int getMember(){
  return member;
 }
 friend int findMax(A a, B b, C c);
};
int findMax(A a, B b, C c){
 int x, y;
 a.member > b.member ? x = a.member : x = b.member;
 c.member > x ? y = c.member : y = x;
 return y;
}
int main(){
 A a(-1);
 B b(-3);
 C c(-5);
 cout<<"Max between the three classes: "<<findMax(a, b, c)<<endl;
 return 0;
}
Comments
Leave a comment