Answer to Question #306142 in C++ for ANKUR

Question #306142

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.


1
Expert's answer
2022-03-04T12:31:27-0500
#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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog