WRITE A PROGRAM FOR DESTRUCTOR IN C++

 Que - make a program for destructor?

#include<iostream>
using namespace std;

class a
{
  public:
  int b,h;
  float area ;
public:

a(int w, int t)
{
  b=w;
  h=t;
}
~a()
{
   area;
   cout<<"\ndestructor run";
}
};
int main()
{
  int w, t;
    float area ;
    cout<<"enter breath of triangle :";
   cin>>w;
   cout<<"enter height of triangle :";
   cin>>t;
   a ob (w,t);
   area =0.5*ob.b*ob.h;
cout<<"area of triangle is :"<<area;
   
    return 0;
}

Result:-



Post a Comment

Previous Post Next Post