Design a class to represent a Employee details. Include the following members.
Data Members • Employee Name • Employee ID • Department Name •Basic Salary. Methods • To assign initial values • compute Net salary * print employee details. To Incorporate a constructor to provide initial values and array of objects.
#include <iostream>
#include <string>
using namespace std;
class Employee
{
string EmpName;
int EmpId;
string DepName;
float BasicSalary;
public:
//Default constructor
Employee(){}
//Parametrized constructor
Employee(string _EmpName, int _EmpId, string _DepName, float _BasicSalary)
:EmpName(_EmpName), EmpId(_EmpId), DepName(_DepName), BasicSalary(_BasicSalary){}
void Assign()
{
cout << "Please, enter Employee Name: ";
cin>> EmpName;
cout << "Please, enter Employee ID: ";
cin >> EmpId;
cout << "Please, enter Department Name: ";
cin >> DepName;
cout << "Please, enter Basic Salary: ";
cin >> BasicSalary;
}
float ComputeNetSalary()
{
float taxes, allows;
cout << "Please, enter taxes (from 0 to 40): ";
cin >> taxes;
cout << "Please, enter allowances (from 0 to 100): ";
cin >> allows;
taxes = taxes / 100;
allows =allows / 100;
return (BasicSalary + BasicSalary*allows - BasicSalary*taxes);
}
void Print()
{
cout << "\nEmployee Name: " << EmpName
<< "\nEmployee ID: " << EmpId
<< "\nDepartment Name: " << DepName
<< "\nBasicSalary: " << BasicSalary << endl;
}
};
int main()
{
//Parametrized constructor
Employee a("Jack", 1234, "Workers", 2000);
cout<<"\nNet salary is "<<a.ComputeNetSalary();
a.Print();
Employee b;
b.Assign();
cout << "\nNet salary is " << b.ComputeNetSalary();
b.Print();
Employee arr[5];
for (int i = 0; i < 5; i++)
{
arr[i].Assign();
}
for (int i = 0; i < 5; i++)
{
arr[i].Print();
}
}
Comments
Leave a comment