Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is wrong with this code? How do I make it look like the sample picture wher

ID: 3854029 • Letter: W

Question

What is wrong with this code? How do I make it look like the sample picture where all the numbers are lined up, and all the numbers are calculated like the sample output? Everything else seems to be on the right track.
Sample inputfile # wiLey 35 13.46 JOHNSON 18 10.50 VasKo 50 22.11 Smith 43 16.47 ClaRK 15 13.22 Moore 34 18.76 ALlen 20 13.21 ANDERson 45 10.49 YounG 39 18.50 Baker 31 20.08 JaCKson 18 12.15 TURNER 28 13.41 Harrison 37 12.50 SteVENS 34 10.11 SiMpSoN 29 13.30 Butler 21 14.91 WaLLace 15 19.37 AlEXANDER 37 20.05 BURNS 27 18.85



//CODE:: #include <iostream> #include <string.h> #include <fstream>
using namespace std;
struct employeeType { string name; double hours; double hourlyPay; double amountEarned; };
string format(string str); void readData(employeeType emp[], int& counter, ifstream& fileContent); void bubblesort(employeeType emp[], int count); void weeklyPay(employeeType arr[], int MAX); void printEmployeesAboveAvg(employeeType arr[], int MAX); void printEmployeeData(employeeType arr[], int MAX);
string format(string str) { for (int i = 0; i < str.length(); i++) { if (i == 0) str[i] = toupper(str[i]); else str[i] = tolower(str[i]); } return str; }
void readData(employeeType emp[], int& counter, ifstream& fileContent) { int i = 0; while (fileContent >> emp[i].name >> emp[i].hours >> emp[i].hourlyPay) { emp[i].name = format(emp[i].name); i++; } }
void bubblesort(employeeType arr[], int MAX) { int n = MAX; // Sorting strings using bubble sort bool didSwap; employeeType temp;
do { didSwap = false; //assume there are no swaps
for (int i = 0; i < n - 1; i++) { if (arr[i].name > arr[i + 1].name) { //I am not cheating temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; didSwap = true; //there was a swap... } } } while (didSwap); }
void weeklyPay(employeeType emp[], int MAX) { for (int i = 0; i < MAX; i++) { if (emp[i].hours > 40) { emp[i].amountEarned = emp[i].hourlyPay * emp[i].hours * (1.5); } else { emp[i].amountEarned = emp[i].hourlyPay * emp[i].hours; } } } void printEmployeesAboveAvg(employeeType emp[], int MAX) {
double temp = 0; for (int i = 0; i < MAX; i++) { if(emp[i].name != "") temp = temp + emp[i].amountEarned; } double avarage = temp / MAX; cout << "Employees whose payroll is larger than " << avarage << " (Ave)" << endl; for (int i = 0; i < MAX; i++) { if (emp[i].amountEarned > avarage) if(emp[i].name != "") cout << emp[i].name << endl; } }
void printEmployeeData(employeeType emp[], int MAX) {
cout << "Employee HoursWorked Hourlywage AmournedEarned" << endl; for (int i = 0; i < MAX; i++) { if (emp[i].name != "") cout << emp[i].name << " " << emp[i].hours << " " << emp[i].hourlyPay << " " << emp[i].amountEarned << endl; } }
int main() { ifstream inFile; struct employeeType emp[200]; char fileName[250]; cout << "Enter inputfile: "; cin >> fileName; inFile.open(fileName); int i=0; readData(emp, i, inFile); i = sizeof(emp) / sizeof(emp[0]); bubblesort(emp, i); weeklyPay(emp, i); printEmployeeData(emp, i); printEmployeesAboveAvg(emp, i);
} What is wrong with this code? How do I make it look like the sample picture where all the numbers are lined up, and all the numbers are calculated like the sample output? Everything else seems to be on the right track.
Sample inputfile # wiLey 35 13.46 JOHNSON 18 10.50 VasKo 50 22.11 Smith 43 16.47 ClaRK 15 13.22 Moore 34 18.76 ALlen 20 13.21 ANDERson 45 10.49 YounG 39 18.50 Baker 31 20.08 JaCKson 18 12.15 TURNER 28 13.41 Harrison 37 12.50 SteVENS 34 10.11 SiMpSoN 29 13.30 Butler 21 14.91 WaLLace 15 19.37 AlEXANDER 37 20.05 BURNS 27 18.85


wiLey 35 13.46 JOHNSON 18 10.50 VasKo 50 22.11 Smith 43 16.47 ClaRK 15 13.22 Moore 34 18.76 ALlen 20 13.21 ANDERson 45 10.49 YounG 39 18.50 Baker 31 20.08 JaCKson 18 12.15 TURNER 28 13.41 Harrison 37 12.50 SteVENS 34 10.11 SiMpSoN 29 13.30 Butler 21 14.91 WaLLace 15 19.37 AlEXANDER 37 20.05 BURNS 27 18.85



//CODE:: #include <iostream> #include <string.h> #include <fstream>
using namespace std;
struct employeeType { string name; double hours; double hourlyPay; double amountEarned; };
string format(string str); void readData(employeeType emp[], int& counter, ifstream& fileContent); void bubblesort(employeeType emp[], int count); void weeklyPay(employeeType arr[], int MAX); void printEmployeesAboveAvg(employeeType arr[], int MAX); void printEmployeeData(employeeType arr[], int MAX);
string format(string str) { for (int i = 0; i < str.length(); i++) { if (i == 0) str[i] = toupper(str[i]); else str[i] = tolower(str[i]); } return str; }
void readData(employeeType emp[], int& counter, ifstream& fileContent) { int i = 0; while (fileContent >> emp[i].name >> emp[i].hours >> emp[i].hourlyPay) { emp[i].name = format(emp[i].name); i++; } }
void bubblesort(employeeType arr[], int MAX) { int n = MAX; // Sorting strings using bubble sort bool didSwap; employeeType temp;
do { didSwap = false; //assume there are no swaps
for (int i = 0; i < n - 1; i++) { if (arr[i].name > arr[i + 1].name) { //I am not cheating temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; didSwap = true; //there was a swap... } } } while (didSwap); }
void weeklyPay(employeeType emp[], int MAX) { for (int i = 0; i < MAX; i++) { if (emp[i].hours > 40) { emp[i].amountEarned = emp[i].hourlyPay * emp[i].hours * (1.5); } else { emp[i].amountEarned = emp[i].hourlyPay * emp[i].hours; } } } void printEmployeesAboveAvg(employeeType emp[], int MAX) {
double temp = 0; for (int i = 0; i < MAX; i++) { if(emp[i].name != "") temp = temp + emp[i].amountEarned; } double avarage = temp / MAX; cout << "Employees whose payroll is larger than " << avarage << " (Ave)" << endl; for (int i = 0; i < MAX; i++) { if (emp[i].amountEarned > avarage) if(emp[i].name != "") cout << emp[i].name << endl; } }
void printEmployeeData(employeeType emp[], int MAX) {
cout << "Employee HoursWorked Hourlywage AmournedEarned" << endl; for (int i = 0; i < MAX; i++) { if (emp[i].name != "") cout << emp[i].name << " " << emp[i].hours << " " << emp[i].hourlyPay << " " << emp[i].amountEarned << endl; } }
int main() { ifstream inFile; struct employeeType emp[200]; char fileName[250]; cout << "Enter inputfile: "; cin >> fileName; inFile.open(fileName); int i=0; readData(emp, i, inFile); i = sizeof(emp) / sizeof(emp[0]); bubblesort(emp, i); weeklyPay(emp, i); printEmployeeData(emp, i); printEmployeesAboveAvg(emp, i);
}
Description A company is planning to hire a number of temporary workers who are paid hourly and you are given a data file that contains the last name of the employees, the amount of hours worked by the employee for the week, and their hourly wage. You are asked to write a program that computes each employee's weekly pay and the average salary of all the workers. The program then outputs the weekly pay of each employee, the average weekly pay, and the names of all the employees whose pay is greater than or equal to the average pay (Sorted by the last name, you will also need to format the name so the first letter is capital and the rest are lower case, using the format function). If the number of hours worked in a week is more than 40 hours, then the pay rate for the hours over 40 is 1.5 times the regular hourly rate for each hour above 40. In this assignment, instead of using parallel arrays, you will use an array of structs to hold the employees' names, hours worked, hourly pay, and amount earned, the definition of the struct can be seen below struct employeeType string name; double hours; double hourlyPay; double amountEarned; Where string name holds the name of the employee, double hours wl hold the hours the employee has worked, double hourlyPay wl hold the hourly pay for the employee, and double amountEarned wi be the total weekly wage. So unlike the last assignment, you won't have two parallel arrays, you wl have an array of structs and each element of the array will hold all the information for each employee. You will write the following functions string format (string) this function wl format the string passed as a parameter and return this string in the format where the first letter is upper cased and the rest of the characters wil be lower cased void readData (employeeType[], int&, ifstream&) this function takes in the struct array of the employee's info, the array counter, and the input filestream, you will populate the struct array with the elds of each struct and you will increment the array counter contents of the file into the appropriate f after each line has been read void bubblesort (employeeType[], int) this function takes the struct array with its counter and will sort the array by name

Explanation / Answer

You need to set width of columns and aligned them left in printEmployeeData method. For that you need to import #include <iomanip> lib. Your printEmployeeData method would become something like this:

void printEmployeeData(employeeType emp[], int MAX) {

cout << "Employee HoursWorked Hourlywage AmournedEarned" << endl;
for (int i = 0; i < MAX; i++) {
if (emp[i].name != "")
//setw means set width between columns according to the their sizes
cout << setw(21) << left << emp[i].name << setw(12) << emp[i].hours
<< setw(18) << emp[i].hourlyPay << emp[i].amountEarned
<< endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote