I'm currently working on an assignment for college, in which I must write a library of classes to support a payroll system. One of the classes is failing to function as intended, and after many hours of trial/error I have decided to slam on the brakes and attempt to seek help!
MAIN
PAYE HEADER
PAYE MemberFunctionF ile
USC HEADER
USC MFF
Employee HEADER
Employee MFF
Payslip MFF
Payslip Header
The PAYSLIP prints out the PRSI, but it does not print out the USC/PAYE, and the odd time when I'm messing with the code trying to find a fix PAYE prints out "-127", which is subtracted from PAYE after calculating it. From this I know that there must be a problem in the paye/usc_method(), however I am still unable to find a fix.
Paye/USC Methods
Any input/help is greatly appreciated. It's due in this week!
MAIN
Code:
#include <iostream>
#include <iomanip>
#include "paye.h"
#include "paye.cpp" /// paye_balance
#include "prsi.h"
#include "prsi.cpp" /// PRSI
#include "usc.h"
#include "usc.cpp" /// usc_balance
#include "employee.h"
#include "employee.cpp" /// NEW_EMPLOYEE
#include "bank.h"
#include "bank.cpp" /// BANK_CLASS
#include "display.h"
#include "display.cpp" /// DISPLAY_CLASS
#include "payslip.h"
#include "payslip.cpp" /// PAYSLIP
double tax_credit[4] = {62.25, 50.67, 59.80, 65.80};
float hourly_rate[4];
double paye_balance[4];
double usc_balance[4];
double eeprsi[4];
double erprsi[4];
double gross_amount[4];
using namespace std;
main()
{
for (int i=0;i<1;i++)
{
/// Creating the 4 acocunts used
new_employee account1();
new_employee account2();
permanent_employee account3();
temporary_employee account4();
///***** ACCOUNT 1 *****
/// Transfer gross pay
gross_amount[0] = account1.get_grosspay();
/// PAYE class
paye_class acc1_paye();
acc1_paye.pass_gross_paye(double gross_amount);
acc1_paye.paye_method();
paye_balance[0] = acc1_paye.get_paye();
/// USC class
usc_class acc1_usc();
acc1_usc.pass_gross_usc(double gross_amount);
acc1_usc.usc_method();
usc_balance[0] = acc1_usc.get_usc();
/// PRSI class
prsi_class acc1_prsi;
acc1_prsi.pass_gross_prsi(gross_amount[0]);
acc1_prsi.prsi_method();
eeprsi[0] = acc1_prsi.get_eeprsi();
erprsi[0] = acc1_prsi.get_erprsi();
account1.get_grosspay();
account1.get_grosstax(paye_balance[0], usc_balance[0]);
account1.get_nettax(tax_credit[0]);
/// Class 4 Payslip
pay_slip payslip1( int employee_no, double gross_pay, double basic_hours, double hourly_rate, double eeprsi, double erprsi, double usc_balance, double paye_balance, double gross_tax, double tax_credit, double net_tax ) ;
payslip1.display_payslip() ;
///********** ACCOUNT 2 **********
new_employee account2;
paye_class acc2_paye;
usc_class acc2_usc;
pay_slip payslip1( int employee_no, double gross_pay, double basic_hours, double hourly_rate, double eeprsi, double erprsi, double usc_balance, double paye_balance, double gross_tax, double tax_credit, double net_tax ) ;
payslip1.display_payslip() ;
///********** ACCOUNT 3 **********
new_employee account3;
paye_balance_class acc3_paye_balance;
acc3_paye_balance.pass_gross_paye_balance(gross_amount[2]);
acc3_paye_balance.paye_balance_method();
paye_balance[2] = acc3_paye_balance.get_paye_balance();
usc_balance_class acc3_usc_balance;
acc3_usc_balance.pass_gross_usc_balance(gross_amount[2]);
acc3_usc_balance.usc_balance_method();
usc_balance[2] = acc3_usc_balance.get_usc_balance();
account3.pay_slip(usc_balance[2], paye_balance[2], tax_credit[2]);
///********** ACCOUNT 4 **********
new_employee account4;
paye_balance_class acc4_paye_balance;
acc4_paye_balance.pass_gross_paye_balance(gross_amount[3]);
acc4_paye_balance.paye_balance_method();
paye_balance[3] = acc4_paye_balance.get_paye_balance();
usc_balance_class acc4_usc_balance;
acc4_usc_balance.pass_gross_usc_balance(gross_amount[3]);
acc4_usc_balance.usc_balance_method();
usc_balance[3] = acc4_usc_balance.get_usc_balance();
account4.pay_slip(usc_balance[3], paye_balance[3], tax_credit[3]);
}
}
PAYE HEADER
Code:
/// Declaration of paye class
/// OOP A2 Padraig McKeefry
#if !defined paye
#define paye
class paye_class /// CREATE EMPLOYEE PAYROLL RECORD AND CALCULATE PAYE
{
public:
void pass_gross_paye(double gross_amount);
double paye_method();
double get_paye() ;
private:
double paye_charge ;
double weekly_gross ;
} ;
#endif
PAYE MemberFunctionF ile
Code:
/// memfunctions1.cpp
/// Employee PAYE
/// OOP A2 Padraig McKeefry
#include <iostream>
#include <iomanip>
#include "paye.h"
using namespace std ;
void paye_class::pass_gross_paye(double gross_amount)
{
weekly_gross = gross_amount;
}
double paye_class::paye_method() /// CALCULATING PAYE DUE
{
if(weekly_gross <= 630.77)
{
paye_charge = ((weekly_gross )* .2);
}
if(weekly_gross > 630.77)
{
paye_charge = ((weekly_gross - 630.77)*.41)+126.15;
}
}
double paye_class::get_paye()
{
return paye_charge ;
}
USC HEADER
Code:
/// usc.h
/// Declaration of usc class
/// OOP A2 Padraig McKeefry
#if !defined usc
#define usc
class usc_class /// Declaring usc_class
{
public:
void pass_gross_usc(double gross_amount);
double usc_method() ;
double get_usc() ;
private:
double usc_charge ;
double weekly_gross;
} ;
#endif
USC MFF
Code:
/// usc.cpp
/// Employee USC
/// OOP A2 Padraig McKeefry
#include <iostream>
#include <iomanip>
#include "usc.h"
using namespace std ;
void usc_class::pass_gross_usc(double gross_amount)
{
weekly_gross = gross_amount;
}
double usc_class::usc_method()
{
if(weekly_gross <= 193)
{
usc_charge = ((weekly_gross)* 0.02);
}
if(weekly_gross > 193 and weekly_gross <= 308)
{
usc_charge = ((weekly_gross - 193) * 0.04) + 3.86;
}
if(weekly_gross > 308)
{
usc_charge = ((weekly_gross - 501) * 0.07) + 8.46;
}
}
double usc_class::get_usc()
{
return usc_charge ;
}
Employee HEADER
Code:
/// DECLARATION OF new_employee CLASS
#if !defined employee
#define employee
class new_employee /// This is the base class. IT IS USED TO CREATE AN EMPLOYEE RECORD
{ /// ITS CHARACTERISTICS CAN BE INHERITED BY THE PERMANENT_EMPLOYEE CLASS
public:
new_employee();
double get_grosspay() ;
private:
double basic_hours ;
double hourly_rate ;
double gross_pay ;
double gross_tax ;
double net_tax ;
double net_pay ;
int bank_acc_no[4] ;
} ;
#endif
Employee MFF
Code:
/// New Employee Class
#include <iostream>
#include <iomanip>
#include "employee.h"
using namespace std ;
int employee_no = 100;
int bank_acc_no[4] = {80045001, 80045002, 80045003, 80045004};
new_employee::new_employee()
{
employee_no = employee_no + 1;
cout << "Enter details for employee no " << employee_no << endl;
cout << "Basic weekly hours: " << endl;
cin >> basic_hours;
cout << "Weekly hourly rate: " << endl;
cin >> hourly_rate;
gross_pay = hourly_rate * basic_hours;
}
double new_employee::get_grosspay()
{
return gross_pay ;
}
///*****************************************************************************
/// PERMANENT_NEW_EMPLOYEE CLASS INHERITS THE CHARACTERISTICS OF NEW_EMPLOYEE
class permanent_employee : public new_employee /// This is the derived class.
{
public:
private:
} ;
///*****************************************************************************
/// PERMANENT_NEW_EMPLOYEE CLASS INHERITS THE CHARACTERISTICS OF NEW_EMPLOYEE
class temporary_employee : public new_employee /// This is the derived class.
{
public:
private:
} ;
Payslip MFF
Code:
// Program example P8B
// Demonstration of a payslip class constructor.
#include <iostream>
#include <iomanip>
#include "payslip.h"
using namespace std ;
pay_slip::pay_slip( int employee_no, double gross_amount, double basic_hours, double hourly_rate, double eeprsi, double erprsi, double usc_balance, double paye_balance, double tax_credit )
{
emp_no = employee_no ;
gross = gross_amount ;
hours = basic_hours;
rate = hourly_rate;
ee_prsi = eeprsi;
er_prsi = erprsi;
usc_tax = usc_balance;
paye_tax = paye_balance;
tax_cred = tax_credit ;
}
void pay_slip::display_payslip()
{
cout << "______________________________________" << endl;
cout << " " << endl;
cout << " Employee Payslip " << endl;
cout << "______________________________________" << endl;
cout << " " << endl;
cout << "Employee No. : " << emp_no << endl;
cout << "Basic Hours : " << hours << endl;
cout << "Hourly Rate : " << rate << endl;
cout << " " << endl;
cout << "Gross pay : " << gross << endl;
cout << " " << endl;
cout << "Employee PRSI : " << fixed << setprecision(2) << ee_prsi << endl;
cout << "Employer PRSI : " << fixed << setprecision(2) << er_prsi << endl;
cout << "USC : " << fixed << setprecision(2) << usc_tax << endl;
cout << "PAYE : " << fixed << setprecision(2) << paye_tax << endl;
cout << " " << endl;
cout << "Gross Tax : " << (paye_tax + usc_tax + ee_prsi) << endl;
cout << "- Tax Credit : " << tax_cred << endl;
cout << "Net Tax : " << (tax_gross - tax_cred) << endl;
cout << " " << endl;
cout << "Net Pay : " << gross - (tax_gross - tax_cred) << endl;
cout << " " << endl;
cout << "______________________________________" << endl;
cout << " " << endl;
}
Payslip Header
Code:
/// Declaration of usc class
/// OOP A2 Padraig McKeefry
#if !defined payslip
#define payslip
class pay_slip
{
public:
pay_slip( int employee_no, double gross_pay, double basic_hours, double hourly_rate, double eeprsi, double erprsi, double usc_balance, double paye_balance, double tax_credit ) ;
void display_payslip() ;
private:
int emp_no ;
double gross ;
double net;
double hours ;
double rate ;
double ee_prsi ;
double er_prsi ;
double usc_tax ;
double paye_tax ;
double tax_gross ;
double tax_cred ;
double tax_net ;
} ;
#endif
The PAYSLIP prints out the PRSI, but it does not print out the USC/PAYE, and the odd time when I'm messing with the code trying to find a fix PAYE prints out "-127", which is subtracted from PAYE after calculating it. From this I know that there must be a problem in the paye/usc_method(), however I am still unable to find a fix.
Paye/USC Methods
Code:
PAYE METHOD
double paye_class::paye_method() /// CALCULATING PAYE DUE
{
if(weekly_gross <= 630.77)
{
paye_charge = ((weekly_gross )* .2);
}
if(weekly_gross > 630.77)
{
paye_charge = ((weekly_gross - 630.77)*.41)+126.15;
}
}
USC METHOD
double usc_class::usc_method()
{
if(weekly_gross <= 193)
{
usc_charge = ((weekly_gross)* 0.02);
}
if(weekly_gross > 193 and weekly_gross <= 308)
{
usc_charge = ((weekly_gross - 193) * 0.04) + 3.86;
}
if(weekly_gross > 308)
{
usc_charge = ((weekly_gross - 501) * 0.07) + 8.46;
}
}

Comment