Write a C++ program that will read 10 records into an array from a data file. Ea
ID: 3767020 • Letter: W
Question
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. Description DataType Variables Employee IDs of INT employees_jd Hours Worked of DOUBLE hrworked_jd Pay Rate of DOUBLE payrate_jd Total Pay of Double total_pay Excluding the main function, your program should have three additional functions that will get the employee id, hours worked, and payrate; another to calculate the total pay; and another to write your output to the output file. 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. Note: _jd represents the initials of the programmer. Your function names should be named by replacing the initials jd with your first and last initials Read Input File Calculate Pay Output Results Name of function get_jd calc_jd prt_jd Properties of function Called from main Called from main Called from main Definition of Function Should pass employee id, hours worked and payrate Should pass hours worked and payrate and calculate total pay Should pass employee id, hours worked, payrate and total pay and write data. This program is the same as the above program but with an ouput data file and the first part is an input data file.
Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
class Record{
public:
int employees_id;
double hrworked;
double payrate;
Record(){
employees_id=0;
hrworked=0;
payrate=0;
}
};
int get_employeeid(Record r){
return r.employees_id;
}
double get_hrworked(Record r){
return r.hrworked;
}
double get_payrate(Record r){
return r.payrate;
}
double totalpay(Record r){
if(r.hrworked<=40){
return r.hrworked*r.payrate;
}
else{
return r.hrworked*r.payrate + ((r.hrworked-40)/5)*(r.hrworked*r.payrate*0.1);
}
}
int main(){
ifstream inf;
inf.open("input.txt");
Record arr[10];
int eid;
double whrs;
double prate;
for(int i=0;i<10;i++){
inf>>eid>>whrs>>prate;
Record r;
r.employees_id=eid;
r.hrworked=whrs;
r.payrate=prate;
arr[i]=r;
}
ofstream outf;
outf.open("output.txt");
for(int i=0;i<10;i++){
outf<<arr[i].employees_id<<" "<<arr[i].hrworked<<" "<<arr[i].payrate<<" "<<totalpay(arr[i])<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.