The output is sent to an output file. Read the file cont and display the output
ID: 3804732 • Letter: T
Question
The output is sent to an output file.
Read the file cont and display the output on the screen
program must check for the output file existence, if the file does not exist or a wrong name is entered, an error message must be displayed.
( i.e the areas), pass the addresses of your files to the functions by reference.
It must include functions and input and output flags in the same program. it must include prototype, call and header functions.
Please read the instructions carefully.
#include <iomanip>
#include<iostream>
#include<string>
using namespace std;
void Print_Employee_Details(string * firstName , string * middleName, string * lastName,double *ratePerHour,
int *hoursWorked,double *grossIncome,double *stateTax,double *fedTax,double *unionTax,double *netIncome);
int main()
{
//SET number of employees as 2.
const int numberOfEmployees=2;
//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_Employee_Details(&firstName[employee], &middleName[employee],
//&lastName[employee], &ratePerHour[employee],&hoursworked[employee],
//&grossIncome[employee],&stateTax[employee],
//&fedTax[employee],&unionTax[employee]&netncome[employee]);
Print_Employee_Details(&firstName[employee] , &middleName[employee],
& lastName[employee],&ratePerHour[employee],&hoursWorked[employee],
&grossIncome[employee],&stateTax[employee],&fedTax[employee],&unionTax[employee],
&netIncome[employee]);
}
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;
}
void Print_Employee_Details(string * firstName , string * middleName, string * lastName,double *ratePerHour,int *hoursWorked,
double *grossIncome,double *stateTax,double *fedTax,double *unionTax,double *netIncome)
{
//print employee firstname
cout<< *firstName<<" "<<setw(3);
//middle
cout<<*middleName<<" "<<setw(3);
//last
cout<<*lastName;
//print rate per hour
cout<<" "<<setw(5)<<*ratePerHour;
//print number of hours worked
cout<<setw(5)<<*hoursWorked;
//print gross income
cout<<setw(5)<<" $"<<*grossIncome;
//print state tax
cout<<setw(5)<<" $"<<*stateTax;
//print fed tax
cout<<setw(5)<<" $"<<*fedTax;
//print union tax
cout<<setw(5)<<" $"<<*unionTax;
//print net income
cout<<setw(5)<<" $"<<*netIncome<<endl;
Explanation / Answer
#include <iomanip>
#include<iostream>
#include<string>
using namespace std;
void Print_Employee_Details(string * firstName , string * middleName, string * lastName,double *ratePerHour,
int *hoursWorked,double *grossIncome,double *stateTax,double *fedTax,double *unionTax,double *netIncome);
int main()
{
//SET number of employees as 2.
const int numberOfEmployees=2;
//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_Employee_Details(&firstName[employee], &middleName[employee],
//&lastName[employee], &ratePerHour[employee],&hoursworked[employee],
//&grossIncome[employee],&stateTax[employee],
//&fedTax[employee],&unionTax[employee]&netncome[employee]);
Print_Employee_Details(&firstName[employee] , &middleName[employee],
& lastName[employee],&ratePerHour[employee],&hoursWorked[employee],
&grossIncome[employee],&stateTax[employee],&fedTax[employee],&unionTax[employee],
&netIncome[employee]);
}
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;
}
void Print_Employee_Details(string * firstName , string * middleName, string * lastName,double *ratePerHour,int *hoursWorked,
double *grossIncome,double *stateTax,double *fedTax,double *unionTax,double *netIncome)
{
//print employee firstname
cout<< *firstName<<" "<<setw(3);
//middle
cout<<*middleName<<" "<<setw(3);
//last
cout<<*lastName;
//print rate per hour
cout<<" "<<setw(5)<<*ratePerHour;
//print number of hours worked
cout<<setw(5)<<*hoursWorked;
//print gross income
cout<<setw(5)<<" $"<<*grossIncome;
//print state tax
cout<<setw(5)<<" $"<<*stateTax;
//print fed tax
cout<<setw(5)<<" $"<<*fedTax;
//print union tax
cout<<setw(5)<<" $"<<*unionTax;
//print net income
cout<<setw(5)<<" $"<<*netIncome<<endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.