Question: // This program uses hours, pay rate, state tax and fed tax to determine gross // and net pay. #include #include #include using namespace std;
// This program uses hours, pay rate, state tax and fed tax to determine gross
// and net pay.
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Fill in the code to define payfile as an input file
float gross;
float net;
float hours;
float payRate;
float stateTax;
float fedTax;
cout << fixed << setprecision(2) << showpoint;
// Fill in the code to open payfile and attach it to the physical file
// named payroll.dat
// Fill in code to write a conditional statement to check if payfile
// does not exist.
{
cout << "Error opening file. \n";
cout << "It may not exist where indicated" << endl;
return 1;
}
cout << "Payrate Hours Gross Pay Net Pay"
<< endl << endl;
// Fill in code to prime the read for the payfile file.
// Fill in code to write a loop condition to run while payfile has more
// data to process.
{
payfile >> payRate >> stateTax >> fedTax;
gross = payRate * hours;
net = gross - (gross * stateTax) - (gross * fedTax);
cout << payRate << setw(15) << hours << setw(12) << gross
<< setw(12) << net << endl;
payfile >> // Fill in the code to finish this with the appropriate
// variable to be input
}
payfile.close();
return 0;
}
Exercise 1: Assume that the data file has hours, payRate, stateTax, and fedTax on one line for each employee. stateTax and fedTax are given as decimals (5% would be .05). Complete this program by filling in the code (places in bold).
Exercise 2: Run the program. Note: the data file does not exist so you should get the error message:
Error opening file.
It may not exist where indicated.
Exercise 3: Create a data file with the following information:
40
15.00
.05
.12
50
10
.05
.11
60
12.50
.05
.13
Save it in the same folder as the .cpp file. What should the data file name be?
1: Run the program. Record the output here:
2: Change the program so that the output goes to an output file called pay.out and run the program. You can use any logical internal name you wish for the output file.
Step by Step Solution
There are 3 Steps involved in it
To complete the program follow these steps Step 1 Define payfile as an input file and open it cpp Define payfile as an input file stream ifstream payf... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
609a5bca8ceec_30534.pdf
180 KBs PDF File
609a5bca8ceec_30534.docx
120 KBs Word File
