Write a program to find the greatest of three numbers using friend function
Answers
{
Void friends (iint a , int b , int c)
{
If (a>b&&a>c)
System.out.println ("the greatest number is "+a);
else if(b> a&&b> c)
System.out.println ( " the greatest number is " + b);
else if (c> a&&c> b)
System.out.println ( " the greatest number is " + c);
}
}
Hope it helps
Thank u ★ ★ ★
#ckc
Answer:
Write a program to find the greatest of three numbers using friend function
Explanation:
#include<iostream>
using namespace std;
class Test {
private:
int x, y, z;
public:
void input() {
cout << "Enter three numbers:";
cin >> x >> y>>z;
}
friend void find(Test t);
};
void find(Test t) {
if (t.x > t.y && t.x > t.z) {
cout << "Largest is:" << t.x;
} else if (t.y > t.z) {
cout << "Largest is:" << t.y;
} else {
cout << "Largest is:" << t.z;
}
}
int main() {
Test t;
t.input();
find(t);
return 0;
}
Output:
Enter three numbers:10 30 20
Largest is:30
What is friend function with example?
In object-oriented programming, a friend function, that is a "friend" of a given class, is a function that is given the same access as methods to private and protected data. A friend function is declared by the class that is granting access, so friend functions are part of the class interface, like methods.
What is friend function in C++ with example?
Advertisements. A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.
Write a program to find the greatest of three numbers using friend function
https://brainly.in/question/3031894
Write a program to find the greatest of three numbers using friend function
https://brainly.in/question/3081894
#SPJ3