Create a class Circle having a data member radius. The class should be capable of calculating the area. Compare the areas of two circles and also displaying the area of which circle is greater. Make all the necessary function as needed including constructors.
#include <iostream>
#define PI 3.14159
using namespace std;
class Circle
{
float radius;
public:
Circle (){}
Circle(float _radius):radius(_radius) {}
void Assign()
{
cout << "Please, enter a radius: ";
cin >> radius;
}
float CalculateArea()
{
return PI*radius*radius;
}
bool IsMoreArea(Circle& c)
{
if (CalculateArea() > c.CalculateArea())
return true;
else
return false;
}
};
int main()
{
Circle a(24);
cout <<"Area of a: "<<a.CalculateArea()<<endl;
Circle b;
b.Assign();
cout << "Area of b: " << b.CalculateArea()<<endl;
if (a.IsMoreArea(b))
cout << "The area of a is more than area of b";
else
cout << "The area of b is more than area of a";
}
Comments
Leave a comment