Using DEVC++ I sorted the netpays in order but i now need to sort them using an
ID: 3834899 • Letter: U
Question
Using DEVC++ I sorted the netpays in order but i now need to sort them using an array of pointers
#include
#include
using namespace std;
main()
{
char employeeid[100][10];
char firstname[100][15], lastname[100][15];
char maritalstatus[100];
double hourlyrate[100], grosspay[100], netpay[100], taxrate[100], maritalrate[100], taxamount[100], regularpay[100], overtimepay[100];
int hoursworked[100], overtimehours[100];
int counter = 0;
int i,netpaySUM=0,j,temp;
double netPayAVG;
cout<<"ENTER EMPLOYEE ID, MARITAL STATUS(S,M,H), FIRST NAME, LAST NAME, HOURS WORKED, HOURLY RATE"< cout<<"ctrl z to end"< while(cin>>employeeid[counter]>>maritalstatus[counter]>>firstname[counter]>>lastname[counter]>>hoursworked[counter]>>hourlyrate[counter])
counter = counter+1;
for(i=0;i { //loop for overtimepay
if (hoursworked[i] > 40)
overtimehours[i] = (hoursworked[i] - 40);
overtimepay[i] = overtimehours[i] * (hourlyrate[i] * 1.5);
if (hoursworked[i] < 40)
overtimepay[i] = 0;
}
for(i=0;i { //loop for grosspay
grosspay[i] =(hoursworked[i] * hourlyrate[i]) + overtimepay[i];
regularpay[i] = (grosspay[i] - overtimepay[i]);}
for(i=0;i if(grosspay[i] > 1000) taxrate[i] = 0.30;
else if(grosspay[i] > 800) taxrate[i] = 0.20;
else if(grosspay[i] > 500) taxrate[i] = 0.10;
else if(grosspay[i] >= 0) taxrate[i] = 0.0;
}
for(i=0;i if(maritalstatus[i] == 'S') maritalrate[i] += 0.05;
else if(maritalstatus[i] == 'H') maritalrate[i] -= 0.05;
else taxrate[i];}
for(i=0;i taxamount[i] = (grosspay[i] * (taxrate[i] + maritalrate[i]));}
for(i=0;i netpay[i] = grosspay[i] - taxamount[i];
netpaySUM=netpaySUM+netpay[i];
}
//Netpay before sorting
cout<<"Netpay before sorting ";
for(i=0;i cout<
Explanation / Answer
//use this function
//Declare this function before main()
void sortnetpay(double*, int);//take array's base address and size of the array
//Call this function in main()
void main()
{
double *p;
p= netpay;//assign the base address to pointer
sortnetpay(p,10);
}
//Function Definition
void sortnetpay(double *arrayPointer, int size)
{
double temp;
cout<<"The array Elements before sorting are:-->";
for(int i=0;i<size;i++)
{
cout<<*arrayPointer<<" ";
arrayPointer++;
}
for(int i=0;i<size;i++)
{
for(int j=i+1;j<size;j++)
{
if(arrayPointer[i]>arrayPointer[j])
{
temp =arrayPointer[i];
arrayPointer[i]=arrayPointer[j];
arrayPointer[j]=temp;
}
}
}
cout<<"The array Elements after sorting:-->";
for(int i=0;i<size;i++)
{
cout<<*arrayPointer<<" ";
arrayPointer++;
}
}
//if you need any help regarding this question. Leace comment!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.