PROGRAM 3
CONSTRUCTOR OVERLOADING
/* Define a Class Employee taking employee
number and salary as Private members and having default, parameterized, copy
constructor and destructor. Parameters should be passed dynamically to the
parameterized constructor. Take values dynamically from main ( ) . */
#include<iostream.h>
class employee
{
int eno;
float salary;
public:
employee()
{
cout<<"\n default
constructor invoked";
eno=0;
salary=0.0;
}
employee(int a,float b)
{
eno=a;
salary=b;
cout<<"\n
parameterized constructor invoked";
}
employee(employee &e)
{
eno=e.eno;
salary=e.salary;
cout<<"\n copy
constructor invoked";
}
~employee()
{
cout<<"\n
destructor at work";
}
};
void main()
{
employee e;
int x;
float y;
cout<<"\n enter
employee number : ";
cin>>x;
cout<<"\n enter
salary : ";
cin>>y;
employee e1(x,y);
cout<<"\n enter
employee number : ";
cin>>x;
cout<<"\n enter
salary : ";
cin>>y;
employee e2(x,y);
employee e3=e2;
}
No comments:
Post a Comment