Answer to Question #172850 in C++ for KAVIN MUKILAN

Question #172850

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)


1
Expert's answer
2021-03-19T19:20:15-0400
#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 (:";
    }
}

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