Header Ads

Employee Management System Project Step by Step using Java and C++

In this Post we Discuss Employee Management System Project using Java and C++. An Abstract class Employee with a constructor and Two abstract Methods along with two subclasses Permanent Employee and Visiting Employee that inherit from the Employee class in java and C++


Program Source Code using Java

import java.util.*;

abstract class Employee{

protected int empId;

protected String empName;

// Constructor

public Employee(int employeeId, String employeeName) {

this.empId = employeeId;

this.empName = employeeName;

}

// Abstract Method

abstract void inputDetail();

abstract double calculateSalary();

public void displayInfo() {

System.out.println("-----------Employee Detail-------");

System.out.println("Employee ID :"+empId);

System.out.println("Employee Name :"+empName);

}

}

class parmanentEmployee extends Employee{

private double basicSalary,allowance;

//constructor

public parmanentEmployee(int empId, String empName) {

super(empId,empName);

}

@Override

public void inputDetail() {

Scanner ins = new Scanner(System.in);

System.out.print("Enter Basic Salary :$");

basicSalary = ins.nextDouble();

System.out.print("Enter Allowance :$");

allowance = ins.nextDouble();

}

@Override

public double calculateSalary() {

return basicSalary+allowance;

}

}

class VisitingEmployee extends Employee{

private int workedHour;

private double hourlyRate;

public VisitingEmployee(int empId,String empName){

super(empId,empName);

}@Override

public void inputDetail() {

Scanner ins = new Scanner(System.in);

System.out.print("Enter Hourly Rate :");

hourlyRate = ins.nextDouble();

System.out.print("Enter Hour :");

workedHour = ins.nextInt();

}

@Override

public double calculateSalary() {

return workedHour*hourlyRate;

}

}

public class EmployeeEx {


public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner ins = new Scanner(System.in);

Employee Pemployee = new parmanentEmployee(0,"");

Employee Vemployee = new VisitingEmployee(0,"");

char op;

do {

System.out.println("Select Employee Type");

System.out.println("1. Permanet Employee");

System.out.println("2. Visiting Employee");

System.out.print("Enter Your Choice :");

int choice =ins.nextInt();

switch(choice) {

case 1:{

System.out.print("Enter Employee Id :");

int id = ins.nextInt();

System.out.print("Enter Employee Name :");

String name = ins.next();

Pemployee.empId = id;

Pemployee.empName = name;

Pemployee.inputDetail();

double sal = Pemployee.calculateSalary();

Pemployee.displayInfo();

System.out.println("Calculated Salary :"+sal);

break;

}

case 2:{

System.out.print("Enter Employee Id :");

int id = ins.nextInt();

System.out.print("Enter Employee Name :");

String name = ins.next();

Vemployee.empId = id;

Vemployee.empName = name;

Vemployee.inputDetail();

double sal = Vemployee.calculateSalary();

Vemployee.displayInfo();

System.out.println("Calculated Salary :"+sal);

break;

}

default:

System.out.println("Invalid Number Try Again");

break;

}

System.out.print("Do You Want to Continue(y/n):");

op = ins.next().charAt(0);

}while(op=='y'||op=='Y');

}

}

Related Video:


Program Source Code using C++

#include<iostream>
#include<string>
using namespace std;
//abstract Class
class Employee{
protected:
int empId;
string name;
public:
//concrete method
void InputBasicInfo(){
cout<<"Enter Employee ID :";
cin>>empId;
cout<<"Enter Employee Name :";
cin.ignore();
getline(cin,name);
}
void DisplayBasicInfo()const{
cout<<"---------- Basic Information -------------"<<endl;
cout<<"Employee ID :"<<empId<<endl;
cout<<"Employee Name :"<<name<<endl;
}
//Pure Virtual Function
virtual void inputInfo() = 0;
virtual void calculateSalary() const= 0;
};
//dirived Class Visiting Employee 
class visitingEmp : public Employee{
private:
int numberOfDays;
float dailyWages;
public:
//@Override
void inputInfo(){
cout<<"Enter Daily Wages :";
cin>>dailyWages;
cout<<"Enter Number of Days :";
cin>>numberOfDays;
}
//@Override
void calculateSalary() const{
float salary = dailyWages*numberOfDays;
cout<<"Salary :"<<salary<<endl;
}
};
//darived Class Parmanet Employee 
class ParmanentEmp : public Employee{
private:
int monthlySalary;
public:
void inputInfo(){
cout<<"Enter Monthly Salary :";
cin>>monthlySalary;
}
void calculateSalary() const{
cout<<"Salary :"<<monthlySalary<<" Per Month"<<endl;
}
};
main(){
Employee *Emp;
int choice;
do{
cout<<"-------- Main Menu ----------\n";
cout<<"1. Create Visiting Employee \n";
cout<<"2. Create Parmanent Employee \n";
cout<<"0. Exit \n";
cout<<"Enter Your Choice :";
cin>>choice;
switch(choice){
case 1:
Emp = new visitingEmp();
break;
case 2:
Emp = new ParmanentEmp();
break;
case 0:
cout<<"Exiting The Program \n";
break;
default:
cout<<"Invalid Number : Plz Enter Valid Number \n";
continue;
}
if(choice != 0){
Emp->InputBasicInfo();
Emp->inputInfo();
cout<<"\nEmployee Information\n";
Emp->DisplayBasicInfo();
Emp->calculateSalary();
delete Emp;
}
}while(choice!=0);
}


Related Video




No comments

Powered by Blogger.