C++ constructor with arguments

A constructor with arguments are constructor having same name as that of a class, in which it is define and accepts input parameters to initialize the data members of a class as arguments.

Program:

/*PROGRAM TO IMPLEMENT PARAMETERIZED CONSTRUCTOR*/

#include<iostream.h>

#include<conio.h>

class area

{

int length,breadth;

public:

area(int l,int b)

{

length=l;

breadth=b;

cout<<“Length of rectangle is:”<<length<<endl;

cout<<“Breadth of rectangle is: “<<breadth<<endl;

}

void display()

{

cout<<“Area of rectangle is: “<<length*breadth;

}

};

void main()

{

clrscr();

area a1(8,7);

a1.display();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *