Tuesday, February 1, 2011

cs201____5 Programming

#include<iostream.h>
static int iRefCount=0;
class CRectangle
{
      private:
              int iBot;
              int iRight;
          
       public:
              int area();
              int gettop()
              {
                  return iBot;
              };
              int getright()
              {
                  return iRight;
              };
              void set_value(int t,int r)
              {
                   iBot=t;
                   iRight=r;
              };
              CRectangle operator =(CRectangle & c)
              {
                         iRefCount++;
                         iBot=c.iBot;
                         iRight=c.iRight;
                         return *this;
              };
              CRectangle()
              {
                          iRefCount++;
                         
              };
               ~CRectangle()
              {
                          --iRefCount;
                         
              };
                CRectangle(CRectangle & obj)
{
                               
iRefCount++;
                                 
}
                  
             
};

int CRectangle::area()
{
                  int cal=iBot*iRight;
                  return cal;
}
  
  
main()
{
      CRectangle obj,obj1;
      obj.set_value(100,64);
            cout<<"Area of rectangle 1 is : "<<obj.area()<<endl;
     
      obj1.set_value(56,100);
            cout<<"Area of rectangle 2 is : "<<obj1.area()<<endl;
      cout<<"objects   "<<iRefCount<<endl;
      obj=obj1;
      cout<<"After using copy constructor, total number of rectangles is : "<<iRefCount<<endl;
      obj.~CRectangle();
        
      cout<<"objects   "<<iRefCount<<endl;
      system("pause");
      }