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

I need help with this program i need to pass by arrays into the function as poin

ID: 3794984 • Letter: I

Question

I need help with this program i need to pass by arrays into the function as pointers. If you dont understand what to do let me know please.

// Need to pass by arrays into the function as with pointer


#include <iomanip>
#include<iostream>
#include<string>
using namespace std;
int main()
{
//SET number of employees as 5.
const int numberOfEmployees=5;
//declare variables
string firstName[numberOfEmployees];
string middleName[numberOfEmployees];
string lastName[numberOfEmployees];
// char choice;

//declare integer variables
int hoursWorked[numberOfEmployees];
// int overTime=0;
// int totalHours=0;

//declare double variables
double ratePerHour[numberOfEmployees];
double grossIncome[numberOfEmployees];
double totalGrossIncome=0;
double netIncome[numberOfEmployees];
double stateTax[numberOfEmployees];
double fedTax[numberOfEmployees];
double unionTax[numberOfEmployees];
//constant declarations
double STATE_TAX_PERCENTAGE=0.06; //6 %
double FED_TAX_PERCENTAGE=0.12; //12 %
double UNION_TAX_PERCENTAGE=0.02;//2%
//read employee details for 5 persons
for(int employee=0;employee<numberOfEmployees;employee++)
{

  //read employee name
  cout<<"Enter your FIRST NAME :";
  cin>>firstName[employee];
  cout<<"Enter your MIDDLE NAME :";
  cin>>middleName[employee];
  cout<<"Enter your LAST NAME :";
  cin>>lastName[employee];
  //read hours worked
  cout<<"Enter HOURS WORKED :";
  cin>>hoursWorked[employee];
  //read rate per hour
  cout<<"Enter RATE PER HOUR :";
  cin>>ratePerHour[employee];


   
  //check if totalHours is less than 40
  if(hoursWorked[employee]<40)
   grossIncome[employee]=(ratePerHour[employee]*hoursWorked[employee]);
  else
   grossIncome[employee]= ratePerHour[employee]*40+(hoursWorked[employee]-40)*ratePerHour[employee]*1.5;
  //sum all grossIncome for all employess
  totalGrossIncome+=grossIncome[employee];
  //find state tax 6 percent on gross income
  stateTax[employee]= grossIncome[employee]*STATE_TAX_PERCENTAGE;
  //find federal tax 12 percent on gross income
  fedTax[employee]=grossIncome[employee]*FED_TAX_PERCENTAGE;
  //find union tax 2 percent on gross income
  unionTax[employee]=grossIncome[employee]*UNION_TAX_PERCENTAGE;
  //find net income
  netIncome[employee]= grossIncome[employee]-(stateTax[employee]+fedTax[employee]+unionTax[employee]);

}

//print the header

cout<<"Data Housing Corp. Weekly Payroll"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<setw(3)<<"First Name"<<setw(3)<<"MI"<<setw(3)<<"Last name"<<setw(3)<<"Rate per hour"<<setw(3)<<"Hours worked"<<setw(3)<<"Gross Income"<<setw(3)<<"State Tax"<<setw(3)<<"Fed Tax"<<setw(3)<<"Union Tax"<<setw(3)<<"Net Income"<<endl;

for(int employee=0;employee<numberOfEmployees;employee++)
{

  //Print name of employee
  cout<<firstName[employee]<<setw(3)<<middleName[employee]<<setw(3)<<lastName[employee];
  //print rate per hour
  cout<<setw(5)<<ratePerHour[employee];
  //print number of hours worked
  cout<<setw(5)<<hoursWorked[employee];
  //print gross income
  cout<<setw(5)<<" $"<<grossIncome[employee];
  //print state tax
  cout<<setw(5)<<" $"<<stateTax[employee];
  //print fed tax
  cout<<setw(5)<<" $"<<fedTax[employee];
  //print union tax
  cout<<setw(5)<<" $"<<unionTax[employee];
  //print net income
  cout<<setw(5)<<" $"<<netIncome[employee]<<endl;

}

  cout<<"---------x---------*---------"<<endl;

//print total gross income
cout<<"Total gross income : "<<totalGrossIncome<<endl;
//print average total gross income
cout<<"Average gross income : "<<totalGrossIncome/numberOfEmployees<<endl;

//pause program output on console
system("pause");
return 0;
}

Explanation / Answer

// Need to pass by arrays into the function as with pointer


#include <iomanip>
#include<iostream>
#include<string>
using namespace std;
void Print_Employee_Details(string *firstname, string *middleName, string *lastname, int numberOfEmployees){ //Passed array as Pointers

cout<<Do what ever you want to do"<<endl;   //Added by me

}

int main()
{
//SET number of employees as 5.
const int numberOfEmployees=5;
//declare variables
string firstName[numberOfEmployees];
string middleName[numberOfEmployees];
string lastName[numberOfEmployees];
// char choice;

//declare integer variables
int hoursWorked[numberOfEmployees];
// int overTime=0;
// int totalHours=0;

//declare double variables
double ratePerHour[numberOfEmployees];
double grossIncome[numberOfEmployees];
double totalGrossIncome=0;
double netIncome[numberOfEmployees];
double stateTax[numberOfEmployees];
double fedTax[numberOfEmployees];
double unionTax[numberOfEmployees];
//constant declarations
double STATE_TAX_PERCENTAGE=0.06; //6 %
double FED_TAX_PERCENTAGE=0.12; //12 %
double UNION_TAX_PERCENTAGE=0.02;//2%
//read employee details for 5 persons
for(int employee=0;employee<numberOfEmployees;employee++)
{

//read employee name
cout<<"Enter your FIRST NAME :";
cin>>firstName[employee];
cout<<"Enter your MIDDLE NAME :";
cin>>middleName[employee];
cout<<"Enter your LAST NAME :";
cin>>lastName[employee];
//read hours worked
cout<<"Enter HOURS WORKED :";
cin>>hoursWorked[employee];
//read rate per hour
cout<<"Enter RATE PER HOUR :";
cin>>ratePerHour[employee];



//check if totalHours is less than 40
if(hoursWorked[employee]<40)
   grossIncome[employee]=(ratePerHour[employee]*hoursWorked[employee]);
else
   grossIncome[employee]= ratePerHour[employee]*40+(hoursWorked[employee]-40)*ratePerHour[employee]*1.5;
//sum all grossIncome for all employess
totalGrossIncome+=grossIncome[employee];
//find state tax 6 percent on gross income
stateTax[employee]= grossIncome[employee]*STATE_TAX_PERCENTAGE;
//find federal tax 12 percent on gross income
fedTax[employee]=grossIncome[employee]*FED_TAX_PERCENTAGE;
//find union tax 2 percent on gross income
unionTax[employee]=grossIncome[employee]*UNION_TAX_PERCENTAGE;
//find net income
netIncome[employee]= grossIncome[employee]-(stateTax[employee]+fedTax[employee]+unionTax[employee]);

}

Print_Employee_Details(firstName, middleName, lastName,numberOfEmployees ); //Arrays are passed , This is what you wanted

//print the header

cout<<"Data Housing Corp. Weekly Payroll"<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
cout<<setw(3)<<"First Name"<<setw(3)<<"MI"<<setw(3)<<"Last name"<<setw(3)<<"Rate per hour"<<setw(3)<<"Hours worked"<<setw(3)<<"Gross Income"<<setw(3)<<"State Tax"<<setw(3)<<"Fed Tax"<<setw(3)<<"Union Tax"<<setw(3)<<"Net Income"<<endl;

for(int employee=0;employee<numberOfEmployees;employee++)
{

//Print name of employee
cout<<firstName[employee]<<setw(3)<<middleName[employee]<<setw(3)<<lastName[employee];
//print rate per hour
cout<<setw(5)<<ratePerHour[employee];
//print number of hours worked
cout<<setw(5)<<hoursWorked[employee];
//print gross income
cout<<setw(5)<<" $"<<grossIncome[employee];
//print state tax
cout<<setw(5)<<" $"<<stateTax[employee];
//print fed tax
cout<<setw(5)<<" $"<<fedTax[employee];
//print union tax
cout<<setw(5)<<" $"<<unionTax[employee];
//print net income
cout<<setw(5)<<" $"<<netIncome[employee]<<endl;

}

cout<<"---------x---------*---------"<<endl;

//print total gross income
cout<<"Total gross income : "<<totalGrossIncome<<endl;
//print average total gross income
cout<<"Average gross income : "<<totalGrossIncome/numberOfEmployees<<endl;

//pause program output on console
system("pause");
return 0;
}
==========================================================================
I have made the changes reuested, The added part are Highlighted IN bold

Have a look and Thanks and let me know if there is any concern.

void Print_Employee_Details(string *, string *, string *, int);

Prototype that can be used
=======================================================================================

// Need to pass by arrays into the function as with pointer

#include <iomanip>

#include<iostream>

#include<string>

using namespace std;

void Print_Employee_Details(string *, string *, string *, int);

void Print_Employee_Details(string * firstName , string * middleName, string * lastName, int numberOfEmployees){

cout<<"Do You manipulations here"<<endl;

}

int main()

{

//SET number of employees as 5.

const int numberOfEmployees=5;

//declare variables

string firstName[numberOfEmployees];

string middleName[numberOfEmployees];

string lastName[numberOfEmployees];

// char choice;

//declare integer variables

int hoursWorked[numberOfEmployees];

// int overTime=0;

// int totalHours=0;

//declare double variables

double ratePerHour[numberOfEmployees];

double grossIncome[numberOfEmployees];

double totalGrossIncome=0;

double netIncome[numberOfEmployees];

double stateTax[numberOfEmployees];

double fedTax[numberOfEmployees];

double unionTax[numberOfEmployees];

//constant declarations

double STATE_TAX_PERCENTAGE=0.06; //6 %

double FED_TAX_PERCENTAGE=0.12; //12 %

double UNION_TAX_PERCENTAGE=0.02;//2%

//read employee details for 5 persons


for(int employee=0;employee<numberOfEmployees;employee++)

{

//read employee name

cout<<"Enter your FIRST NAME :";

cin>>firstName[employee];

cout<<"Enter your MIDDLE NAME :";

cin>>middleName[employee];

cout<<"Enter your LAST NAME :";

cin>>lastName[employee];

//read hours worked

cout<<"Enter HOURS WORKED :";

cin>>hoursWorked[employee];

//read rate per hour

cout<<"Enter RATE PER HOUR :";

cin>>ratePerHour[employee];

//check if totalHours is less than 40

if(hoursWorked[employee]<40)

   grossIncome[employee]=(ratePerHour[employee]*hoursWorked[employee]);

else

   grossIncome[employee]= ratePerHour[employee]*40+(hoursWorked[employee]-40)*ratePerHour[employee]*1.5;

//sum all grossIncome for all employess

totalGrossIncome+=grossIncome[employee];

//find state tax 6 percent on gross income

stateTax[employee]= grossIncome[employee]*STATE_TAX_PERCENTAGE;

//find federal tax 12 percent on gross income

fedTax[employee]=grossIncome[employee]*FED_TAX_PERCENTAGE;

//find union tax 2 percent on gross income

unionTax[employee]=grossIncome[employee]*UNION_TAX_PERCENTAGE;

//find net income

netIncome[employee]= grossIncome[employee]-(stateTax[employee]+fedTax[employee]+unionTax[employee]);

}

Print_Employee_Details(firstName, middleName, lastName,numberOfEmployees ); //Arrays are passed , This is what you wanted

//print the header

cout<<"Data Housing Corp. Weekly Payroll"<<endl;

cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;

cout<<setw(3)<<"First Name"<<setw(3)<<"MI"<<setw(3)<<"Last name"<<setw(3)<<"Rate per hour"<<setw(3)<<"Hours worked"<<setw(3)<<"Gross Income"<<setw(3)<<"State Tax"<<setw(3)<<"Fed Tax"<<setw(3)<<"Union Tax"<<setw(3)<<"Net Income"<<endl;

for(int employee=0;employee<numberOfEmployees;employee++)

{

//Print name of employee

cout<<firstName[employee]<<setw(3)<<middleName[employee]<<setw(3)<<lastName[employee];

//print rate per hour

cout<<setw(5)<<ratePerHour[employee];

//print number of hours worked

cout<<setw(5)<<hoursWorked[employee];

//print gross income

cout<<setw(5)<<" $"<<grossIncome[employee];

//print state tax

cout<<setw(5)<<" $"<<stateTax[employee];

//print fed tax

cout<<setw(5)<<" $"<<fedTax[employee];

//print union tax

cout<<setw(5)<<" $"<<unionTax[employee];

//print net income

cout<<setw(5)<<" $"<<netIncome[employee]<<endl;

}

cout<<"---------x---------*---------"<<endl;

//print total gross income

cout<<"Total gross income : "<<totalGrossIncome<<endl;

//print average total gross income

cout<<"Average gross income : "<<totalGrossIncome/numberOfEmployees<<endl;

//pause program output on console

system("pause");

return 0;

}