Write a program to find out greatest among three numbers. Define two classes, first class KBC contain two data members a and b, and second class BBC only one data member c. Input data to the data members by defining appropriate member functions. A member function max() defined in second class BBC to find out the greatest among three numbers. Solve this problem by using friend function.
#include <iostream>
using namespace std;
class BBC;
class KBC {
private:
int a,b;
friend void compare(KBC n1,BBC n2);
public:
void getData(){
cout<<"\nEnter first number: ";
cin>>a;
cout<<"\nEnter second number: ";
cin>>b;
}
};
class BBC {
private:
int c;
friend void compare(KBC n1,BBC n2);
public:
void getData(){
cout<<"\nEnter third number: ";
cin>>c;
}
void max(){
}
};
void compare(KBC n1,BBC n2) {
if(n1.a >= n1.b && n1.a >= n2.c)
cout << "Largest number: " << n1.a;
if(n1.b >= n1.a && n1.b >= n2.c)
cout << "Largest number: " << n1.b;
if(n2.c >= n1.a && n2.c >= n1.b)
cout << "Largest number: " << n2.c;
}
int main (){
KBC n1;
BBC n2;
n1.getData();
n2.getData();
compare(n1,n2);
return 0;
}
Comments
Leave a comment