Question
Please help me fix this following C++ code to match the required output, thanks, Code: #include #include #include #include using namespace std; struct employee{ string
Please help me fix this following C++ code to match the required output, thanks,
Code:
#include
#include
#include
#include
using namespace std;
struct employee{
string name;
int numHours;
double hourlyRate;
double payment;
employee(){
}
employee(string n, int hours, double rate){
name = n;
numHours = hours;
hourlyRate = rate;
}
};
int readData(string fileName, employee employees[]){
int count = 0;
string name;
int numHours;
double hourlyRate;
ifstream in(fileName.c_str());
if(in.is_open()){
while(in >> name >> numHours >> hourlyRate){
employees[count++] = employee(name, numHours, hourlyRate);
}
}
else{
cout
exit(-1);
}
return count;
}
void calculateWeeklyPay(employee employees[], int size){
for(int i = 0; i
if(employees[i].numHours
employees[i].payment = employees[i].numHours * employees[i].hourlyRate;
else
employees[i].payment = (40 * employees[i].hourlyRate) + ((employees[i].numHours - 40) * (1.5 * employees[i].hourlyRate));
}
}
double calculateAveragePay(employee employees[], int size){
double total = 0;
for(int i = 0; i
total += employees[i].payment;
}
return total / size;
}
void printEmployeesWithPayHigherThanAverage(employee employees[], int size){
double avg = calculateAveragePay(employees, size);
cout
for(int i = 0; i
if(employees[i].payment >= avg){
cout
}
}
cout
}
void printEmployeeDetails(employee employees[], int size){
cout
for(int i = 0; i
cout
}
}
int main(){
employee employees[100];
int size = readData("ch8_Ex17Data.txt", employees);
calculateWeeklyPay(employees, size);
printEmployeeDetails(employees, size);
cout
printEmployeesWithPayHigherThanAverage(employees, size);
return 0;
}
requied text file name and its content
ch8_Ex17Data.txt
Johnson 60 12.50 Aniston 65 13.25 Cooper 50 14.50 Gupta 70 14.75 Blair 55 10.50 Clark 40 18.75 Kennedy 45 20.50 Bronson 60 20.00 Sunny 65 18.75 Smith 30 9.75
required output, results that is highlighted in green are the one currently the code provided fulfill, and the red ones are not fulfill
Results Bronson 60.0020.001400.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started