C++ program to read employee details using parameterized constructor

#include<iostream.h>
using namespace std;
class Employee
{
private:
int empid;
char empname[20];
int bsalary;
int allowance;
public:
Employee()
{
bsalary = 1000;
}
void GetData();
void DispData();
};
void Employee::GetData()
{
cout<<"Enter the employee id: "; cin>>empid;
cout<<"Enter the employee name: "; cin>>empname;
cout<<"Enter the employee allowance: "; cin>>allowance;
}
void Employee::DispData()
{
cout<<endl<<empid<<"\t"<<empname<<"\t"<<bsalary
<<"\t"<<allowance;
}
int main()
{
Employee e[3];
cout<<"Enter the employee information:"<<endl;
for(int i=0;i<3;i++)
{
e[i].GetData();
}
cout<<endl<<"The employee information is:";
cout<<endl<<"EmpID \t Name \t Bsalary \t Allowance";
for(int i=0; i<3;i++)
{
e[i].DispData();
}
}

 

Output:

C++ program to read employee details using parameterized constructor

Leave a Reply

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