The perfect place for easy learning...

OOPs using C++

×

List of Programs


C++ Practical Programs


Aim


Given that an EMPLOYEE class contains following members: data members: Employee number, Employee name, Basic, DA, IT, Net Salary and print data members.

Procedure


  • Step 1 - Include the required header files (iostream.h, conio.h, and windows.h for colors).
  • Step 2 - Create a class (employee) with the following members as public members.
    • emp_number, emp_name, emp_basic, emp_da, emp_it, and emp_net_sal as data members.
    • get_emp_details(), find_net_salary() and show_emp_details() as member functions.
  • Step 3 - Implement all the member functions with their respective code (Here, we have used scope resolution operator ::).
  • Step 3 - Create a main() method.
  • Step 4 - Create an object (emp) of the above class inside the main() method.
  • Step 5 - Call the member functions get_emp_details() and show_emp_details().
  • Step 6 - returnn 0 to exit form the program execution.

Implementation


C++ Program
#include <windows.h>
#include <iostream>

using namespace std;

class employee
{
	int   emp_number;
	char  emp_name[20];
	float emp_basic;
	float emp_da;
	float emp_it;
	float emp_net_sal;

	public:

		void get_emp_details();
		float find_net_salary(float basic, float da, float it);
		void show_emp_details();
};

void employee :: get_emp_details()
{
	cout<<"\nEnter employee number: ";
	cin>>emp_number;
	cout<<"\nEnter employee name: ";
	cin>>emp_name;
	cout<<"\nEnter employee basic: ";
	cin>>emp_basic;
	cout<<"\nEnter employee DA: ";
	cin>>emp_da;
	cout<<"\nEnter employee IT: ";
	cin>>emp_it;
}

float employee :: find_net_salary(float basic, float da, float it)
{
    return (basic+da)-it;
}

void employee :: show_emp_details()
{
	cout<<"\n\n**** Details of  Employee ****";
	cout<<"\nEmployee Name      :  "<<emp_name;
	cout<<"\nEmployee number    :  "<<emp_number;
	cout<<"\nBasic salary       :  "<<emp_basic;
	cout<<"\nEmployee DA        :  "<<emp_da;
	cout<<"\nIncome Tax         :  "<<emp_it;
	cout<<"\nNet Salary         :  "<<find_net_salary(emp_basic, emp_da, emp_it);
	cout<<"\n-------------------------------\n\n";
}


int main()
{
    employee emp;
    
    emp.get_emp_details();
    emp.show_emp_details();

    return 0;
}

Result



   Download Source Code

Place your ad here
Place your ad here