Thursday, January 6, 2011

Program to Show Constructor Overloading

#include
#include
class rectangle
{
private:
int length,breadth;
public:
rectangle()
{
length=breadth=0;
cout<<"\n\nContructor with 0 Parameter is called";
}
rectangle(int a)
{
length=breadth=a;

cout<<"\n\nConstructor with 1 Parameter is called\n";
}
rectangle(int a,int b)
{
length=a;
breadth=b;
cout<<"\n\nContructor with 2 Parameters is called";
}
int area()
{
return(length*breadth);
}
};
int main()
{
clrscr();
rectangle r1;
rectangle r2(5);
rectangle r3(7,8);
cout<<"\n\nArea of first rectangle="<cout<<"\n\nArea of second rectangle="<cout<<"\n\nArea of third rectangle="<cout<<"\nBy:Abhishek Wadhwa";
getch();
return 0;
}

/******************************************
OUTPUT
********************************************

Contructor with 0 Parameter is called

Constructor with 1 Parameter is called

Contructor with 2 Parameters is called

Area of first rectangle=0

Area of second rectangle=25

Area of third rectangle=56

By Abhishek Wadhwa
*/

1 comment:

Programming the Whole World!