Answer to Question #232350 in C++ for Arup

Question #232350

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.


1
Expert's answer
2021-09-03T15:16:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS