I have 3 questions, this is related to C++ The first one is about the instructio
ID: 3838251 • Letter: I
Question
I have 3 questions, this is related to C++
The first one is about the instructions they seemed a bit obtuse,
" netpay average
Calculate the average of all employee net pays (salary). Display the computations and average of at least 5 employees. "
Does this mean it wants an average of all 5 employees to spit out one number or each 'individual' employee's average salary? I went with the second one.
The second question is sorting the netpay it says to do this with either sort exchange or selection. It wants me to sort the salary, and to display the netpay before the sort and after the sort.
The Third problem is sorting the netpay with pointers. "Sort the net pays (salary) using an array of pointers (do not change the data in the original array).
For now, display only the net pays before sorting Sort the net pays (salary) using an array of pointers
(do not change the data in the original array). For now, display only the net pays before sorting and after sorting."
This is the base for the three separate programs, The first one is done unless, I misread the instructions. But the two other programs I really don't know where to begin. Iv been looking
up information on selection sort and pointers but I'm not sure how to apply that to my current program.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int i;
int ID[4];
double hWorked[10], hRate[10], oTime[10], oTimePay[10], Gross[10], tRate[10], tAmount[10], nPay[10], RegP[10];
char mStatus;
string firstname[10], lastname[10];
for (i = 0; i < 5; i++)
{
cout << "Please enter your first name " << endl;
cin >> firstname[i];
cout << endl;
cout << "Please enter your last name " << endl;
cin >> lastname[i];
cout << endl;
cout << "Please enter the last four of your social security number. " << endl;
cin >> ID[i];
cout << endl;
cout << "How many hours did this employee work this week? " << endl;
cin >> hWorked[i];
cout << endl;
cout << "What is the pay rate for this employee? " << endl;
cin >> hRate[i];
cout << endl;
cout << "What is the Marital Status of this Employee? S for single and M for Married or H as the Head of the Household: " << endl;
cin >> mStatus;
cout << endl;
//calculations
oTime[i] = hWorked[i] - 40;
oTimePay[i] = oTime[i] * hRate[i];
oTimePay[i] = oTimePay[i] * 1.5;
Gross[i] = (hWorked[i] * hRate[i]) + oTime[i];
//Tax Rate solution
if (Gross[i] > 1000)
{
tRate[i] = 0.30;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else if (Gross[i] >= 800 && Gross[i] <= 1000)
{
tRate[i] = 0.20;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else if (Gross[i] >= 500 && Gross[i] <= 800)
{
tRate[i] = 0.10;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else
{
tRate[i] = 0.00;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
//Marital Status Tax Addition or Break
if (mStatus == 'S' || mStatus == 's')
{
tRate[i] += 0.05;
cout << "Your Single this means you get an additional 5 percent added to your taxes this year. ";
cout << "Your Tax Rate is now, " << tRate[i] << endl;
}
if (mStatus == 'H' || mStatus == 'h')
{
tRate[i] -= 0.05;
cout << "Enjoy a 5 percent tax break as the head of the house hold! ";
cout << "Your Tax rate is now, " << tRate[i] << endl;
}
tAmount[i] = Gross[i] * tRate[i];
nPay[i] = Gross[i] - tAmount[i];
RegP[i] = Gross[i] - oTimePay[i];
}
for (i = 0; i < 5; i++)
{
//Display
cout << endl;
cout << fixed;
cout << setprecision(2);
cout << "Dr. Ebrahimi's Payroll Institute " << endl;
cout << left << setw(15) << firstname[i] << lastname[i] << endl;
cout << left << setw(15) << "SSN: " << ID[i] << endl;
cout << left << setw(15) << "HW: " << hWorked[i] << endl;
cout << left << setw(15) << "HR: " << hRate[i] << endl;
cout << left << setw(15) << "OTH: " << oTime[i] << endl;
cout << left << setw(15) << "OTP: " << oTimePay[i] << endl;
cout << left << setw(15) << "REGP: " << RegP[i] << endl;
cout << left << setw(15) << "Gross: " << Gross[i] << endl;
cout << left << setw(15) << "Tax: " << tAmount[i] << endl;
cout << left << setw(15) << "NET: " << nPay[i] << endl;
cout << endl;
}
system("pause");
return 0;
}
Any help would be very much appreciated!
edit: whoops added the wrong code
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int i;
int ID[4];
double hWorked[10], hRate[10], oTime[10], oTimePay[10], Gross[10], tRate[10], tAmount[10], nPay[10], RegP[10];
char mStatus;
string firstname[10], lastname[10];
for (i = 0; i < 5; i++)
{
cout << "Please enter your first name " << endl;
cin >> firstname[i];
cout << endl;
cout << "Please enter your last name " << endl;
cin >> lastname[i];
cout << endl;
cout << "Please enter the last four of your social security number. " << endl;
cin >> ID[i];
cout << endl;
cout << "How many hours did this employee work this week? " << endl;
cin >> hWorked[i];
cout << endl;
cout << "What is the pay rate for this employee? " << endl;
cin >> hRate[i];
cout << endl;
cout << "What is the Marital Status of this Employee? S for single and M for Married or H as the Head of the Household: " << endl;
cin >> mStatus;
cout << endl;
oTime[i] = hWorked[i] - 40;
oTimePay[i] = oTime[i] * hRate[i];
oTimePay[i] = oTimePay[i] * 1.5;
Gross[i] = (hWorked[i] * hRate[i]) + oTime[i];
if (Gross[i] > 1000)
{
tRate[i] = 0.30;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else if (Gross[i] >= 800 && Gross[i] <= 1000)
{
tRate[i] = 0.20;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else if (Gross[i] >= 500 && Gross[i] <= 800)
{
tRate[i] = 0.10;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
else
{
tRate[i] = 0.00;
cout << "Your Tax Rate is " << tRate[i] << endl;
}
if (mStatus == 'S' || mStatus == 's')
{
tRate[i] += 0.05;
cout << "Your Single this means you get an additional 5 percent added to your taxes this year. ";
cout << "Your Tax Rate is now, " << tRate[i] << endl;
}
if (mStatus == 'H' || mStatus == 'h')
{
tRate[i] -= 0.05;
cout << "Enjoy a 5 percent tax break as the head of the house hold! ";
cout << "Your Tax rate is now, " << tRate[i] << endl;
}
tAmount[i] = Gross[i] * tRate[i];
nPay[i] = Gross[i] - tAmount[i];
RegP[i] = Gross[i] - oTimePay[i];
}
for (i = 0; i < 5; i++)
{
cout << endl;
cout << fixed;
cout << setprecision(2);
cout << "Dr. Ebrahimi's Payroll Institute " << endl;
cout << left << setw(15) << firstname[i] << lastname[i] << endl;
cout << left << setw(15) << "SSN: " << ID[i] << endl;
cout << left << setw(15) << "HW: " << hWorked[i] << endl;
cout << left << setw(15) << "HR: " << hRate[i] << endl;
cout << left << setw(15) << "OTH: " << oTime[i] << endl;
cout << left << setw(15) << "OTP: " << oTimePay[i] << endl;
cout << left << setw(15) << "REGP: " << RegP[i] << endl;
cout << left << setw(15) << "Gross: " << Gross[i] << endl;
cout << left << setw(15) << "Tax: " << tAmount[i] << endl;
cout << left << setw(15) << "NET: " << nPay[i] << endl;
cout << endl;
}
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.