Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Did I do this C++ Payroll Program correctly? Write three separate programs by expanding the existing payroll program Program 1- netpay average Calculate the average

Did I do this C++ Payroll Program correctly?

Write three separate programs by expanding the existing payroll program

Program 1- netpay average Calculate the average of all employee net pays (salary). Display the computations and average of at least 5 employees.

Here is how I did program 1, was this correct?

#include

#include

#include

using namespace std;

struct Employee

{

string employeename;

int salary; // 0 - 100

};

int main()

{

float sum,average,average1,sum1;

int n;

cout<<"Enter no. of employees: ";

cin>>n;

Employee empList[n];

//Creating Array of n employees

for (int i = 0; i

{

//Input data of n employees

cout<<"Enter Employee's name': ";

cin>>empList[i].employeename;

cout<<"Salary: ";

cin>>empList[i].salary;

sum1+=empList[i].salary;

}

average1=sum1/n;

cout << "Average Salary of all employees = " << average;

//Process data of 5 employees

for(int i=0; i<5; ++i)

{

sum+=empList[i].salary;

}

average=sum/5;

cout << " Average Salary of 5 employees = " << average<

system("pause");

return 0;

}

Program 2 - sort netpay (regular sort- exchange or selection) Sort the net pays (salary). For now, display only the net pays before sorting and after sorting.

Here is how I did Program 2, was this correct?

#include

#include

#include

using namespace std;

//SWAP

void selection_sort(double arr[], int size) {

int i, j;

for(i=0; i

{

for(j=i+1; j

{

if(arr[i]>arr[j])

{

double temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

}

}//SWAP

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];

float sum = 0, average = 0;

int n;

cout << "Enter no. of employees: ";

cin >> n;

for (i = 0; i < n; 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];

// Averageing

sum += nPay[i];

average = sum / n;

}

for (i = 0; i < n; 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;

}

cout << left << setw(15) << "SUM: " << sum << endl;

cout << left << setw(15) << "Average: " << average << endl;

int scan, pass, n1 = 10, i1;

cout << " Before sort: " << endl;

for (i1 = 0; i1

if(nPay[i]>0)

cout << nPay[i1] << " ";

}

cout << endl;

//testing

selection_sort(nPay,sizeof(nPay)/sizeof(nPay[0]));

cout << " After sort: " << endl;

for (i1 = 0; i1

if(nPay[i]>0.00)

cout << nPay[i1] << " ";

}

cout << endl;

//testing */

system("pause");

return 0;

}

Program 3 - Sort the netpay by the 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.

Here is how I did program 3, was this correct?

#include

void sort(int *pointer, int size){

//Sorting the array using the pointers

int i, j, temp;

for(i = 0; i < size; i++){

for(j = i + 1; j < size; j++){

if(*(pointer+j) < *(pointer+i)){

temp = *(pointer+j);

*(pointer+j) = *(pointer+i);

*(pointer+i) = temp;

}

}

}

}

int main(){

printf("Enter size of array:");

int size;

scanf("%d",&size);

int netpays[size];

int duplicate[size];

int i;

printf("Enter the netpays:");

//Taking the array of numbers from user

for(i=0;i

scanf("%d",&netpays[i]);

}

printf("Before Sort NetPays ");

// Printing the elements of array before sorting

for(i=0;i

printf("%d ", netpays[i]);

duplicate[i] = netpays[i];

}

printf(" ");

sort(duplicate, size);

// Printing the elements after sorting

printf("Sorted NetPays: ");

for(i=0;i

printf("%d ", duplicate[i]);

}

printf(" ");

// Printing the Original array

printf("Original NetPays ");

for(i=0;i

printf("%d ", netpays[i]);

}

printf(" ");

}

Was all 3 of these correct?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions