C++ Program to find area of circle using constructor
Program
#include <iostream>
#define PI 3.141
using namespace std;
class AreaCircle
{
private:
float area;
public:
AreaCircle(float radius)
{
area = PI * radius * radius;
}
void display()
{
cout << "Area:\t" << area << endl;
}
};
int main()
{
cout << "Enter value of radius:\t";
int radius;
cin >> radius;
AreaCircle area(radius);
area.display();
return 0;
}
Output
Enter value of radius: 3.4
Area: 28.269