The purpose of this phase is to expand the payroll system to display all employe
ID: 3851944 • Letter: T
Question
The purpose of this phase is to expand the payroll system to display all employee information in a tabular form by including arrays.
A) Display company title and a header that labels the output in a tabular form. Input the first name and last name of an employee.
char firstname[100][10], lastname[100][15];
or you may use
#include
using namespace std;
string firstname[100], lastname[100];
int hw[100],empid[100];
Hint: You may want to use the following I/O manipulators.
#include , setw(15), setprecision(2) setiosflags(ios::fixed|ios::showpoint|ios::left)
PAYROLL INSTITUTE
SSN
HW
HR
OTH
OTP
REGP
GROSS
TAX
NET
===
113
50
20
10
300
800
1100
385
715
223
45
15
5
112.5
675
787.5
275
512.5
B) Take advantage of arrays by breaking programs into separate units. Each unit should have a separate loop. (Do not use functions.)
Read all data into arrays
Compute all the overtimepays
Compute all the grosspays
Compute all the taxratesCompute all the netpays
Display all the arrays
C) Include separate functions to read in the data, compute the gross pay, tax rate, net pay, and overtime pay for all employees, and display.
FIRST NAME LAST NAME STATSSN
HW
HR
OTH
OTP
REGP
GROSS
TAX
NET
======== ======== ==== =======
=== ==== ===== ===== ===== ===== ===== Bob Snow M113
50
20
10
300
800
1100
385
715
John Smith M223
45
15
5
112.5
675
787.5
275
512.5
Explanation / Answer
C++ CODE FOR PAYROLL SYSTEM USING FUNCTIONS AND PRINTS IN THE FORM OF TABLE :
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payrollSystem
{
ifstream fin;
char employeeid[10];
char employeename[20];
char maritalstatus;
int hoursworked,overtime;
double hourlyrate,overtimepay,regularpay,grosspay,taxrate,taxamount,netpay, sum, average;
void calculategrosspay();
void calculatetax();
void calculatenetpay();
void printheadings();
void printdata();
void findsum(int);
double findavg(double, int);
public:
payrollSystem();
~payrollSystem();
void printreport();
};
payrollSystem::payrollSystem()
{
fin.open("empinput.txt");
}
payrollSystem::~payrollSystem()
{
fin.close();
}
//method to calculate gross pay
void payrollSystem:: calculategrosspay(){
if(hoursworked>40){
overtime=hoursworked-40;
regularpay=hoursworked*hourlyrate;
overtimepay=overtime*(hourlyrate*1.5);
grosspay=regularpay+overtimepay;
}
else {
grosspay=hoursworked*hourlyrate;
regularpay = hoursworked * hourlyrate;
overtime =0;
overtimepay = 0;
}
}
//method to calculate taxrate
void payrollSystem::calculatetax()
{
if(grosspay>=500) taxrate=.30;
else if(grosspay>200.00) taxrate=.20;
else taxrate=.10;
if(maritalstatus=='S'||maritalstatus=='s')
taxrate=taxrate+.05;
taxamount=grosspay*taxrate;
}
//method to calculate net pay
void payrollSystem::calculatenetpay()
{
netpay=grosspay-taxamount;
}
//method to print headings
void payrollSystem::printheadings()
{
cout<<setw(45)<<"-payrollSystem REPORT-"<<endl;
cout<<"--------------------------------------------------------------------"<<endl;
cout<<"NAME ID HW OT RT-PAY OT-PAY GROSS"
" TAX NETPAY"<<endl;
cout<<"--------------------------------------------------------------------"<<endl;
}
//method to print data
void payrollSystem::printdata()
{
cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<regularpay<<setw(8)
<<overtimepay<<setw(8)<<grosspay<<setw(8)<<taxamount<<setw(8)
<<netpay<<endl;
}
void payrollSystem::findsum(int i)
{
sum+=netpay;
}
double payrollSystem::findavg(double sum, int i)
{
average = sum/i;
cout<<endl<<"The netpay average is "<< average<<endl;
}
void payrollSystem::printreport()
{
int i=0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate)
{
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
i++;
findsum(i);
}//end of while
findavg(sum, i);
}//end of print report
int main()
{
payrollSystem employee;
employee.printreport();
}//end of main
OUTPUT: FOR VALID OUTPUT PLEASE FRAME INPUT FILE ACCORDINGLY....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.