Last active
July 12, 2023 20:33
-
-
Save adbertram/1828e0d2ab903a3b37d5fa63cc75a104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef EMPLOYEE_SALARY_SLIP_H_INCLUDED | |
#define EMPLOYEE_SALARY_SLIP_H_INCLUDED | |
#include <iostream> | |
#include <string> | |
#include "Employee.h" | |
using namespace std; | |
class EmployeeSalarySlip : public Employee { | |
private: | |
double grossSalary; | |
double monthlyBonus; | |
double bonusRate; | |
double annualIncrement; | |
double taxRate; | |
double transportAllowance; | |
double internetAllowance; | |
double housingAllowance; | |
double epfDeduction; | |
double taxDeduction; | |
double netSalary; | |
public: | |
EmployeeSalarySlip() = default; | |
EmployeeSalarySlip(double annualInc, double tax, double transportAL, double internetAL, double housingAL, double bonus) { | |
annualIncrement = annualInc; | |
taxRate = tax; | |
transportAllowance = transportAL; | |
internetAllowance = internetAL; | |
housingAllowance = housingAL; | |
bonusRate = bonus; | |
setGrossSalary(); | |
setMonthlyBonus(); | |
setEpfDeduction(); | |
setTaxDeduction(); | |
setNetSalary(); | |
} | |
void setAnnualIncrement(double annualInc) { | |
annualIncrement = annualInc; | |
} | |
double getAnnualIncrement() { | |
return annualIncrement; | |
} | |
void setTaxRate(double tax) { | |
taxRate = tax; | |
} | |
double getTaxRate() { | |
return taxRate; | |
} | |
void setTransportAllowance(double transportAL) { | |
transportAllowance = transportAL; | |
} | |
double getTransportAllowance() { | |
return transportAllowance; | |
} | |
void setInternetAllowance(double internetAL) { | |
internetAllowance = internetAL; | |
} | |
double getInternetAllowance() { | |
return internetAllowance; | |
} | |
void setHousingAllowance(double housingAL) { | |
housingAllowance = housingAL; | |
} | |
double getHousingAllowance() { | |
return housingAllowance; | |
} | |
void setBonusRate(double bonus) { | |
bonusRate = bonus; | |
} | |
double getBonusRate() { | |
return bonusRate; | |
} | |
void setGrossSalary() { | |
int current_year = 2023; | |
int current_month = 7; | |
int current_day = 13; | |
int workYears = 0; | |
if ((current_month - getJoin_month()) < 0) { | |
workYears = current_year - getJoin_year() - 1; | |
} else if ((current_month - getJoin_month()) == 0) { | |
if ((current_day - getJoin_day()) < 0) { | |
workYears = current_year - getJoin_year() - 1; | |
} else { | |
workYears = current_year - getJoin_year(); | |
} | |
} else { | |
workYears = current_year - getJoin_year(); | |
} | |
double amount = getStart_salary(); | |
double gross_salary = amount; | |
for (int i = 0; i < workYears; i++) { | |
double incrementAmount = gross_salary * (annualIncrement / 100.0); | |
gross_salary += incrementAmount; | |
} | |
grossSalary = gross_salary; | |
} | |
double getGrossSalary() { | |
return grossSalary; | |
} | |
void setMonthlyBonus() { | |
monthlyBonus = grossSalary * (bonusRate / 100.0); | |
} | |
double getMonthlyBonus() { | |
return monthlyBonus; | |
} | |
void setEpfDeduction() { | |
double totalAllowance = transportAllowance + internetAllowance + housingAllowance; | |
epfDeduction = (grossSalary + totalAllowance) * (11 / 100.0); | |
} | |
double getEpfDeduction() { | |
return epfDeduction; | |
} | |
void setTaxDeduction() { | |
taxDeduction = grossSalary * (taxRate / 100.0); | |
} | |
double getTaxDeduction() { | |
return taxDeduction; | |
} | |
void setNetSalary() { | |
netSalary = grossSalary + transportAllowance + internetAllowance + housingAllowance + monthlyBonus - epfDeduction - taxDeduction; | |
} | |
double getNetSalary() { | |
return netSalary; | |
} | |
bool compareCodeNum(Employee& emp1, Employee& emp2) { | |
return emp1.getCode_num() < emp2.getCode_num(); | |
} | |
void bubbleSort(vector<Employee>& person, int size) { | |
bool swap; | |
Employee temp; | |
do { | |
swap = false; | |
for (int i = 0; i < size - 1; i++) { | |
if (person[i].getCode_num() > person[i + 1].getCode_num()) { | |
temp = person[i]; | |
person[i] = person[i + 1]; | |
person[i + 1] = temp; | |
swap = true; | |
} | |
} | |
} while (swap); | |
} | |
int binarySearch(vector<Employee>& person, int numElems, int target) { | |
int first = 0; // First array element | |
int last = numElems - 1; // Last array element | |
int middle = 0; // Midpoint of search | |
int position = -1; // Position of search value | |
bool found = false; // Flag | |
int n = person.size(); | |
bubbleSort(person, n); | |
while (!found && first <= last) { | |
middle = (first + last) / 2; // Calculate midpoint | |
if (person[middle].getCode_num() == target) // If value is found at mid | |
{ | |
found = true; | |
position = middle; | |
} else if (person[middle].getCode_num() > target) // If value is in lower half | |
last = middle - 1; | |
else | |
first = middle + 1; // If value is in upper half | |
} | |
return position; | |
} | |
void displaySalarySlip(vector<Employee>& person, vector<EmployeeSalarySlip>& salarySlips) { | |
int searchCode; | |
cout << "Enter employee code number to print the Salary Slip: "; | |
cin >> searchCode; | |
int index = binarySearch(person, person.size(), searchCode); | |
if (index != -1) { | |
cout << "\nEmployee Code Number: " << person[index].getCode_num() << endl; | |
cout << "Name: " << person[index].getName() << endl; | |
cout << "Gender: " << person[index].getGender() << endl; | |
cout << "Contact Number: " << person[index].getContact_number() << endl; | |
cout << "Joining Date (DD/MM/YYYY): " << person[index].getJoin_day() << "/" << person[index].getJoin_month() << "/" << person[index].getJoin_year() << endl; | |
cout << "Department: " << person[index].getDepartment() << endl; | |
cout << "Designation: " << person[index].getDesignation() << endl; | |
cout << "Start Salary: $" << person[index].getStart_salary() << endl; | |
cout << "Gross Salary: $" << salarySlips[index].getGrossSalary() << endl; | |
cout << "Monthly Bonus: $" << salarySlips[index].getMonthlyBonus() << endl; | |
cout << "EPF Deduction: $" << salarySlips[index].getEpfDeduction() << endl; | |
cout << "Tax Deduction: $" << salarySlips[index].getTaxDeduction() << endl; | |
cout << "Net Salary: $" << salarySlips[index].getNetSalary() << endl; | |
} else { | |
cout << "Employee with code number " << searchCode << " not found!" << endl; | |
} | |
} | |
}; | |
#endif // EMPLOYEE_SALARY_SLIP_H_INCLUDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment