Files and Input #include #include #include #include using namespace std; int main() { //Declare variables string employee; double RateOfPay, salary; int hours;
Files and Input
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
//Declare variables
string employee;
double RateOfPay, salary;
int hours;
cout << fixed << setprecision(2);
ifstream in("WorkLoad.txt");
getline(in, employee);
in >> RateOfPay >> hours;
in.close();
salary = hours * RateOfPay;
if (hours > 38)
salary = (38 * RateOfPay) + ((hours - 38) * RateOfPay * 1.5);
else
salary = hours * RateOfPay;
cout << employee << " worked " << hours << " hours at a rate of pay of " << RateOfPay << ". Due to the number of hours worked the employee did ";
(hours > 38) ? cout << "" : cout << "not ";
cout << "qualify for time and a half pay. The weekly salary for this employee is " << salary << endl;
// open output file Salary.txt for writing
ofstream out("Salary.txt");
out << fixed << setprecision(2);
// write output to the output file
out << employee << " worked " << hours << " hours at a rate of pay of " << RateOfPay << ". Due to the number of hours worked the employee did ";
(hours > 38) ? out << "" : out << "not ";
out << "qualify for time and a half pay. The weekly salary for this employee is " << salary << endl;
out.close();
return 0;
}
Add to the input file WorkLoad.txt of assignment above so that it contains at least 10 employees, in the following format:
First name Last name (2 words)
RateofPay hourWorked (2 numbers)
__________________________________
Line One is the employee’s name, first and last
Line Two is the Rate of Pay followed by the number of hours worked
Your data should contain at least one employees from each category (worked overtime, exactly 38 hours, and less than 38 hours).
Your program is to read in the data contained in the file until end of file is reached. You do not know in advance how many records are in the file
1. If the employee worked more than 38 hours they are to receive time and a half for all the hours worked over 38
2. If the employee worked 38 or fewer hours their salary is hours worked times rate of pay
3. Calculate the weekly take home pay of that employee
4. Print your results on the screen in the following format:
[Employee] worked [hours] at a rate of pay of [Rate of Pay]. Due to the number of hours worked the employee [did/did not] qualify for time and a half pay. The weekly salary for this employee is [salary].
5. What is the average salary of all your employees?
This output is also to be written to an output file Salary.txt
Note:
Employee, hours worked, and Rate of Pay are read in from the input file.
Whether or not the employee qualified for time and a half and the computed salary are based upon the results of an if statement.
Submit the following files:
Copy of input file
Your program with the screen output attached
Copy of the output file
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images