Wednesday, August 28, 2013

C++ program using constructor,destructor

/* C++ program using constructor,destructor */



#include<iostream>
using namespace std;
class t
{
  int hour;
  int min;
 public:
 // void input();
  t(int,int);
  t();
  void display(void)
  {
  cout<<"hour="<<hour<<"\n";
  cout<<"min="<<min<<"\n";
  }
  t(t &t11)
  {
  hour=t11.hour;
  min=t11.min;
  }
  ~t()
  {
   cout<<"\ndestroyed\n";
  }
};
t::t(int h,int m)
  {
   hour=h;
   min=m;
  }
 t::t()
    {
     hour=0;
     min=0;
    }

int main()
{
 t t1;
 cout<<"\nobject1 "<<"\n";
 t1.display();
 t1=t(2,45);
 cout<<"\nobject2"<<"\n";
 t1.display();
 t t2(t1);
 cout<<"\nobject3 "<<"\n";
 t2.display();
 return 0;
}

No comments: