Answer to Question #330461 in C++ for mak

Question #330461

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.

1
Expert's answer
2022-04-19T08:07:04-0400
#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";
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS