Answer:
#include <iostream>
using namespace std;
class Circle{
public:
double radius;
Circle(double r) {
radius = r;
}
double calcArea() {
return 3.14 * radius * radius;
}
};
int main()
{
double radius;
cout<<"Enter the radius: ";
cin >> radius;
Circle ob = Circle(radius);
cout << ob.calcArea() << endl;
return 0;
}
Step-by-step explanation:
Create a class called Circle that has one variable, radius
Create a constructor that takes one parameter, radius
Create a method called calcArea that calculates and returns the area of a circle using given formula
In the main:
Ask the user for the radius
Create an object for Circle with given radius
Call calcArea method to calculate the area, and print the result