Saturday, March 19, 2011

Program for overloading constructors Using OOPs & C++ concept


// overloading class constructors
#include <iostream.h>
#include <conio.h>


class CRectangle
 {
    int width, height;
    public:
    CRectangle ();
    CRectangle (int,int);
    int area (void) 
   {
       return (width*height);
   }
};


CRectangle::CRectangle ()
 {
  width = 5;
  height = 5;
}


CRectangle::CRectangle (int a, int b) 
{
  width = a;
  height = b;
}


void main () 
{
  CRectangle rect (3,4);
  CRectangle rectb;
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  getche();
}

No comments:

Post a Comment