Create a class with four private member variables and five member functions; wri
ID: 3539514 • Letter: C
Question
Create a class with four private member variables and five member functions; write a
program that will read in each record from an input file, calculate the total pay for the thirty (30) employees and storing
the data into an array. The data is to then be printed to an output file.
Description
DataType Members
Employee IDs of INT employees_jd
Hours Worked of DOUBLE hrworked_jd
Pay Rate of DOUBLE payrate_jd
Total Pay of Double total_pay
Class name payroll
Member Functions
calcPay private pass computed Total Pay and store into array.
getinfo private get information from datafile.
putinfo private output data to datafile.
results public array of thirty (30), used to access private function getinfo and calcPay to retrieve data
from input file and calculate Total Pay.
results2 public used to access private function putinfo to write the array of data to an output file.
Total pay should be calculated by multiplying the hours worked by pay rate plus 10% of total pay for every five (5) hours
over forty (40). (i.e. a person working 50 hours with a total pay of $100 would have ((50-40)/5)*(100*.1) added to
total pay.
Data should be printed to this file.
Data file should be named data2_jd.txt
Explanation / Answer
class Member {
public:
int employees_jd;
double hrworked_jd;
double payrate_jd;
double total_pay;
};
class PayRoll {
private:
double calcPay(Member m) {
double pay = m.payrate_jd * m.hrworked_jd;
if (m.hrworked_jd > 40) {
pay += ((.hrworked_jd - 40)/5)*pay*0.1;
}
}
void getinfo(Member &m) {
// function to access info from the input file
}
void putinfo(const Member m) {
//Print info in the output file
}
public:
Member results[30];
void initPayRoll() {
for (int i =0;i < 30; i++) {
results[i] = new Member();
getinfo(results[i]);
results[i].total_pay = calcPay(results[i]);
putinfo(results[i]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.