oooo H20 9:04 AM 100% ehacc hacc edu HACC Harrisburg Area Community Fahringer Co
ID: 3790263 • Letter: O
Question
oooo H20 9:04 AM 100% ehacc hacc edu HACC Harrisburg Area Community Fahringer College CPS 161 Computer Science Program #3 Algorithm Due: 20 points Wednesday, Feb Program Due: Saturday, Feb 13 alarie Task: Compute the weekly pay for each employee at the Wahoo Widget Company. For each employee, you will calculate the base pay according to the appropriate salary category, and then subtract taxes and deductions. Write the program in C++ For each employee, read an employee ID (a 4-digit nteger) and a salary category code (see below). Then read whatever other information mi ight be needed to compute a net salary for that person. Because of occasional employee turn- over, you do not know the exact number ofemployees in advance. Determine how you know when all employees have been processed for this week. You will use a loop to process the employees, but not a counting loop. The Company has established 4 salary ng categories Code 1: Managers. They receive a fixed annual salary of $51,500. Code 2: Factory workers. They receive a fixed wage of 13.85 per hour for the first 40 hours worked each week, then they receive time-and-a-half (1.5 the regular salary) for any overtime Code 3: Sales staff They receive $250 each week, plus a commission that is 5.7% of their gross weekly sales of Code 4: Pieceworkers. The part-time staff receives a fixed fee of $11.30 for each widget they prod They do not uce. pay health insurance or union dues.Explanation / Answer
c++ code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string line;
vector< vector <double> > table;
ifstream myfile ("input.txt");
if (myfile.is_open())
{
// getline (myfile,line);
while ( getline (myfile,line) )
{
std::vector<double> entry;
string buf; // Have a buffer string
stringstream ss(line); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
while (ss >> buf)
tokens.push_back(buf);
int ID = atoi(tokens[0].c_str() ) ;
int emp_code = atoi(tokens[1].c_str() ) ;
if(emp_code == 1)
{
double gross_salary = 51500.0/52.0; double taxes = gross_salary*0.19; double deductions = 27.85;
double netsalary = gross_salary - taxes - deductions;
entry.push_back(ID);entry.push_back(gross_salary); entry.push_back(taxes);
entry.push_back(deductions); entry.push_back(netsalary);
}
else if(emp_code == 2)
{
int hours = 0;
cout << "for Factory worker " << ID << " Enter number of hours worked in this week! ";
cin >> hours;
double gross_salary;
if(hours <=40)
{
gross_salary = 13.5*hours;
}
else
{
gross_salary = (13.5*hours) + (13.5*(hours-40)*1.5);
}
double taxes = gross_salary*0.19; double deductions = 27.85;
double netsalary = gross_salary - taxes - deductions;
entry.push_back(ID);entry.push_back(gross_salary); entry.push_back(taxes);
entry.push_back(deductions); entry.push_back(netsalary);
}
else if(emp_code == 3)
{
double gross_salary = 250;
double sales = 0;
cout << "for Sales staff " << ID << " Enter gross weekly Sales! ";
cin >> sales;
gross_salary = gross_salary + 0.057*gross_salary;
double taxes = gross_salary*0.19; double deductions = 27.85;
double netsalary = gross_salary - taxes - deductions;
entry.push_back(ID);entry.push_back(gross_salary); entry.push_back(taxes);
entry.push_back(deductions); entry.push_back(netsalary);
}
else
{
double gross_salary = 0;
double n_widgets = 0;
cout << "for Pieceworker " << ID << " Enter widgets produced! ";
cin >> n_widgets;
gross_salary = n_widgets*11.30;
double taxes = gross_salary*0.19; double deductions = 0;
double netsalary = gross_salary - taxes - deductions;
entry.push_back(ID);entry.push_back(gross_salary); entry.push_back(taxes);
entry.push_back(0); entry.push_back(netsalary);
}
table.push_back(entry);
}
myfile.close();
cout << "Emp_ID Gross Taxes Deductions netSalary" << endl;
for (int i = 0; i < table.size(); ++i)
{
for (int j = 0; j < 5; j++)
{
cout << (table[i][j])*100.0/100.0 << " " ;
}
cout << endl;
}
}
else
{
cout << "Unable to open file" << endl;
exit(1);
}
}
input.txt
1111 1
2222 2
3333 3
4444 4
Sample Output:
for Factory worker 2222 Enter number of hours worked in this week!
11
for Sales staff 3333 Enter gross weekly Sales!
11
for Pieceworker 4444 Enter widgets produced!
11
Emp_ID Gross Taxes Deductions netSalary
1111 990.385 188.173 27.85 774.362
2222 148.5 28.215 27.85 92.435
3333 264.25 50.2075 27.85 186.192
4444 124.3 23.617 0 100.683
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.