C++ Programming Write a C++ program that will read 10 records into an array from
ID: 3776803 • Letter: C
Question
C++ Programming
Write a C++ program that will read 10 records into an array from a data file. Each record should contain an employee ID, hours worked and pay rate. You should calculate a total pay and then write the record to an output file. The Record written should consist of Employee ID, hours worked, pay rate and total pay.
Total pay should be calculated by multiplying the hours worked by payrate plus 10% of total pay for every five (5) hours over forty (40). (ie a person working 50 hours with a total pay of $100 would have ((50-40)/5)*(100*.1) added to total pay.
Then, write the same program, but this time create a file (datafile) that has your full name, Course name and Date on the first three lines. Write the program to open the output file in append mode and write your output to this file. When the execution of your C++ is complete, your output file should contain your name, course name and date followed by the 10 employee records including their total pay.
DESCRIPTION DATA TYPE VARIABLES Employee ID's of INT employees_id Hours Worked of DOUBLE hrworked_id Pay Rate of DOUBLE payrate_id Total Pay of DOUBLE total_payExplanation / Answer
Note :Please change the name and course name in the program while you are submitting.
____________
empdata.txt ( Save this file under D Drive then the path of the file pointing to it is D:\empdata.txt)
111 45 10.5
222 55 11.5
333 52 12.5
444 55 9.5
555 47 9.0
666 49 9.5
777 51 10.0
888 53 12.0
999 54 12.5
123 53 12.0
___________
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//defines an input stream for the data file
ifstream dataIn;
//Defines an output stream for the data file
ofstream dataOut;
//Declaring variables
int employees_id,empid;
double hrworked_id,hrs;
double payrate_id,payrt;
double total_pay;
//Opening the input file
dataIn.open("D:\empdata.txt");
/* If the file not found in the Specified location
* Display error message
*/
if(dataIn.fail())
cout<<"** Input File Not found **"<<endl;
//Writing the data to the output file
else
{
//creating and Opening the output file
dataOut.open("D:\empsal.txt");
//Writing user information
dataOut<<"Name : Kane Williams."<<endl;
dataOut<<"Course : Computer Science."<<endl;
dataOut<<"Date : Nov 24,2016."<<endl;
dataOut.close();
//creating and Opening the output file in appending mode
dataOut.open("D:\empsal.txt",fstream::out | fstream::app);
dataOut<<"Emp_Id Hours Worked Pay Rate Total Pay"<<endl;
dataOut<<"------ ------------ -------- ---------"<<endl;
while(dataIn>>employees_id>>hrworked_id>>payrate_id)
{
if(hrworked_id>40)
//Calculating the total pay of an employee
total_pay=hrworked_id*payrate_id+((hrworked_id-40)/5)*(payrate_id*0.1);
else
//Calculating the total pay of an employee
total_pay=hrworked_id*payrate_id;
//Writing the total pay of each employee to the output file
dataOut<<employees_id<<" "<<std::fixed<<std::setprecision(2)<<hrworked_id<<" "<<payrate_id<<" "<<total_pay<<endl;
}
}
//Closing the intput file
dataIn.close();
//Closing the output file.
dataOut.close();
return 0;
}
_____________________
output:(We can see this file under D Drive as we specified the path of the output file as D:\empsal.txt )
Name : Kane Williams.
Course : Computer Science.
Date : Nov 24,2016.
Emp_Id Hours Worked Pay Rate Total Pay
------ ------------ -------- ---------
111 45.00 10.50 473.55
222 55.00 11.50 635.95
333 52.00 12.50 653.00
444 55.00 9.50 525.35
555 47.00 9.00 424.26
666 49.00 9.50 467.21
777 51.00 10.00 512.20
888 53.00 12.00 639.12
999 54.00 12.50 678.50
123 53.00 12.00 639.12
_________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.