Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using c++ Objetive: One-dimensional parallel arrays, input/output, Manipulating

ID: 3675730 • Letter: U

Question


Using c++

Objetive: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions.

Problem:

A Company has recently hired you to help them generate a payroll report for all their employees. You are given a data file containing the employee’s data. The data for each employee consists of the employee id, name, hours worked and rate of pay. The number of employees in the file is unknown. However; the last employee id number is 0.You are to read this data into parallel arrays, calculate the gross pay, federal withholdings, state withholdings, hospitalization and net pay for each employee and store each in an array. You should define the followings as constants:

Federal withholding tax rate, 18%

State withholding tax rate, 4.5%

Hospitalization withholding, 2%

Output should be:

A report for all employees written to a file and consisting of the employee name, id number, gross pay and net pay.

Another report written to a different file containing the total gross pay paid to all employees, total federal withholdings, total state withholdings, total hospitalization withholdings and total for all withholdings.

Requirements:

Comment thoroughly.

Every function must have specifications in the form of comments.

Create global constants.

Make sure every function accomplishes a task and is self-contained

Use typedef to define new types as necessary.

Each file has a heading and column labels to identify information.

Must test if data file exists before reading data.

You may need to write additional functions such astotal which returns the total of an array.

main is used as a driver function, no input/output or calculations is done in main, only what is specified.

Requirenment

- typedef is used to define all arrays.

- a counter is used to count the number of elements read.

- generate an error if file does not exist, or if not open.

- a loop reads the data until the trailing value 0 for ID is encountered.

- each function have clear, full and thorough specifications.

- the function getdata () reads the data from the file into arrays.

- the function getdata() returns the number of employees read from the file as its value.

- the function findgross () fills the gross array with calculated data.

- the function findwithholding () accepts the needed data for an employee and returns the withholdings.

- the function findwithholding () is reused to calculate different withholding.

- the function findnet() fills the net array with calculated data.

- the function total () will return the total of its array argument. (reused).

- headings (), prints the headings and column titles, formatted and looks nice.

- data/calculated results are printed with proper spacing and proper formatting.

Explanation / Answer

Code:

#include <iostream>
#include <fstream>
using namespace std;
#define FED_TAX 0.18
#define STATE_TAX 0.045
#define HOSP_TAX 0.02

typedef string names[1000];
typedef int times[1000];
typedef float cost[1000];
names emp_name;
times wrk_hours,ids;
cost rate,gross,net;
int getdata();
void findgross(int cnt);
void findnet(int cnt);
float findwithholding(int id, float percent);
int toatl(int a[], int cnt);
float toatl(float a[], int cnt);
void printPay(int cnt);


int main()
{
int count;
count=getdata();
cout<<count<<endl;
findgross(count);
findnet(count);
printPay(count);

return 0;
}
int getdata()
{
ifstream in("employee.txt");
int id,cnt=0;
string s;
float rt;
while(true)
{
in>>id;
if(id==0)
break;
ids[cnt]=id;
in>>emp_name[cnt];
in>>wrk_hours[cnt];
in>>rate[cnt];
cnt++;
}
return cnt;
}

void findgross(int cnt)
{
int i;
for(i=0;i<cnt;i++)
{
gross[i]=wrk_hours[i]*rate[i];
}
}
void findnet(int cnt)
{
int i;
for(i=0;i<cnt;i++)
{
net[i]=gross[i]-findwithholding(i,FED_TAX)-findwithholding(i,STATE_TAX)-findwithholding(i,HOSP_TAX);
}
}
float findwithholding(int id, float percent)
{
return gross[id]*percent;
}
int toatl(int a[], int cnt)
{
int i,res=0;
for(i=0;i<cnt;i++)
{
res+=a[i];
}
return res;
}

float toatl(float a[], int cnt)
{
int i;
float res=0;
for(i=0;i<cnt;i++)
{
res+=a[i];
}
return res;
}
void printPay(int cnt)
{
ofstream out("payroll.txt");
int i;
headings(out);
for(i=0;i<cnt;i++)
{
out<<emp_name[i]<<" "<<ids[i]<<" "<<gross[i]<<" "<<net[i]<<endl;
}
}
void printTotal(int cnt)
{
ofstream out("totals.txt");
float sum = total(gross,cnt);
out<<"Total gross = "<<sum<<endl;
out<<"total federal tax = "<<sum*FED_TAX<<endl;
out<<"total state tax = "<<sum*STATE_TAX<<endl;
out<<"total hospitalization tax = "<<sum*HOSP_TAX<<endl;
out<<"total netpay = "<<sum*(1-FED_TAX-STATE_TAX-HOSP_TAX)<<endl;
}

Input:(employee.txt)

1 aravind 56 7.8
2 vijay 78 9.8
3 kumar 89 3.9
4 ketineni 87 8.7
0

Output:(payroll.txt):

aravind       1   436.8   329.784
vijay       2   764.4   577.122
kumar       3   347.1   262.061
ketineni       4   756.9   571.459

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote