Area Of Circle using Friend Function - C++Program
Definition Friend Function
If a function is friend function of a class, that friend function is not the actual member of the class.But which function has rights to access to all private and protected members (variables and functions).
For Better Understanding,
- Understanding Friend Function and Characteristics In C++
- Simple Program for Friend Function Using C++ Programming
- Introduction Of Classes ( OOPS )
Area Of Circle Definition
The area of a circle is π (Pi) times the Radius squared, which is written A=πr2.
The area of a circle is written
A=?r2
here,
r = Radius
? = ~3.14
Simple Program for Friend Function
// Area Of Circle using Friend Function - C++Program
// GCC Compiler
#include<iostream>
class AreaOfCircle {
int radius;
public:
void get() {
std::cout << "Enter the radius of Circle : ";
std::cin >> radius;
}
friend float calculate(AreaOfCircle ob);
};
float calculate(AreaOfCircle ob) {
return 3.14 * ob.radius * ob.radius;
}
int main() {
AreaOfCircle object;
object.get();
std::cout<<"\nArea of Circle : "<<calculate(object);
}
Sample Output
Enter the radius of Circle : 5
Area of Circle : 78.5
C++ Function Example Programs
- Simple Example Program for Function In C++
- Simple Example Program for Function Find Smallest Number In C++
- Simple Example Program for Function to Find Factorial In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Area Of Circle using Friend Function - C++Program
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Example Program For Constructor Overloading In C++
- Simple Example Program For Constructor In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Function Template Using C++ Programming