C++ Program showing constructor overloading

Constructor is a member function with the same name as of it’s class.

This program is used to find the perimeter of square using constructor overloading.



Class perimeter


Int l, b, p;


Perimeter ()


Cout<<”\n Enter the value of l and b”;



Perimeter (int a)




Perimeter (int l1, int b1)





Perimeter (perimeter and peri)


l= peri.l;

b= peri.b;


Void calculate ()


P = 2* (l +b)

Cout <<p;



Void main ()


Perimeter obj, obj1 (2), obj2 (2, 3);

Cout<<”\n perimeter of rectangle is”;

Obj. Calculate ();

Cout<<”\n perimeter of square”;

Obj1.calculate ();

Cout<<”\n perimeter of rectangle”;

Obj2.calculate ();

Cout<<”\n perimeter of rectangle”;

Perimeter obj3 (obj2);

obj3.calculate ();

getch ();


Related posts:

  1. Overloading Binary Operator Overloading binary operator An operator requiring two operand is called...
  2. C++ Program Using Constructor and Destructor This is an object oriented programming in c++ to create...
  3. Constructors Constructors Types of constructors Default constructor A constructor without any...
  4. Constructor in C++ Constructor in C++ Constructor is a member function with the...
  5. Default Argument Default argument C++ allows programmers to specify default values for...