Create the class Circle with attribute radius to find the area of circle. Assign the values for data member using copy constructor and display the result. Finally free the resources of data objects using destructor member function. (Note: Area of circle = 3.14 * radius * radius)
#include <cmath>
#include <iostream>
using namespace std;
class Circle
{
public:
Circle(double r) : radius(r) {}
Circle(const Circle &cir) : radius(cir.radius) {}
~Circle()
{
cout << "\nThe destructor was called. There are no resources to release.";
}
double GetArea()
{
return M_PI * radius * radius;
}
double GetCirc()
{
return 2 * M_PI * radius;
}
double GetRad()
{
return radius;
}
void SetRad(double r)
{
radius = r;
}
private:
double radius;
};
int main()
{
cout << "Enter radius of the circle: ";
double radius;
cin >> radius;
Circle circ1 = Circle(radius);
Circle circ2 = Circle(circ1);
if (circ1.GetRad() == circ2.GetRad())
{
cout << "Both circles are equal. Their area is " << circ1.GetArea() << ", circumference is " << circ1.GetCirc();
}
else
{
cout << "Two circles aren't equal (:";
}
}
Comments
Leave a comment