Finding Area of a Ring using destructor in C++ || Destructor || C++
In this, we are going to find Area of a Ring using a Destructor in C++. 
 


The Code given below can be used in TURBO C++ Compilers: -


#include <iostream.h>
#include<conio.h>

class Area
{
public:
    float Radius, radius, area, pi = 3.142;
    Area(float r1, float r2)
    {
        Radius = r1;
        radius = r2;
    }
    void display()
    {
        area = pi * ((Radius * Radius) - (radius * radius));
        cout << "Area of the ring is:- " << area;
    }
    ~Area()
    {
        cout << "\nDestructor is called.";
    }
};
void main()
{
    clrscr();
    float r1, r2;
    cout << "Enter the dimensions of the ring.\nOuter radius (R) =";
    cin >> r1;
    cout << "Inner radius (r) = ";
    cin >> r2;
    Area obj(r1, r2);
    obj.display();
    getch();
}

//..........Coded by YASH ALAPURIA


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

class Area
{
public:
    float Radius, radius, area, pi = 3.142;
    Area(float r1, float r2)
    {
        Radius = r1;
        radius = r2;
    }
    void display()
    {
        area = pi * ((Radius * Radius) - (radius * radius));
        cout << "Area of the ring is:- " << area;
    }
    ~Area()
    {
        cout << "\nDestructor is called.";
    }
};
int main(void)
{
    float r1, r2;
    cout << "Enter the dimensions of the ring.\nOuter radius (R) =";
    cin >> r1;
    cout << "Inner radius (r) = ";
    cin >> r2;
    Area obj(r1, r2);
    obj.display();
}

//..........Coded by YASH ALAPURIA


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post