Adjust program II to make use of methods. Write a method that prompts the user f
ID: 3619162 • Letter: A
Question
Adjust program II to make use of methods.Write a method that prompts the user for hours worked, rate andname. Use parameter passing, and pass by reference.
Write a method that calculates the gross, base and overtime pay,pass by reference.
Write a method that calculates tax, taking as input the gross pay,returning the tax owed.
Calculate the total amount paid (gross pay) for all 5 people. Usethe return value from the method that calculates the gross pay.
Write a print method that generates the output, including the totalamount paid, in addition to the data for each employee.
Example (Sample input & output for one person)
Enter name: Glenn
Enter hourly rate: 2.00
Enter hours worked: 50
Pay to: Glenn
Hours worked: 50.0
Hourly rate: $ 2.00
Gross pay: $110.00
Base pay: $ 80.00
Overtime pay: $ 30.00
Taxes paid: $ 22.00
Net pay: $ 88.00
-------------------------
#include <stdio.h>
#include<stdlib.h>
#include <conio.h>
#include<string.h>
int main()
{int i;
double rate[5], hours[5], tax[5],baseSalary[5],overtimePay[5],grossSalary[5],netPay[5];
char name[5][10];
for(i=0;i<5;i++)
{printf("Enter name: ");
scanf("%s",&name[i]);
printf("Enter hourly rate: ");
scanf("%lf",&rate[i]);
printf("Enter hours worked: ");
scanf("%lf",&hours[i]);
//if the inputs are -1 break out of the loop
if(hours[i]==-1||rate[i]==-1||strcmp(name[i],"-1")==0)
{
exit(0);
}
printf("Pay to: %s ",name[i]);
printf("Hourly rate: %.2f ",rate[i]);
printf("Hours worked: %.2f ",hours[i]);
if(hours[i]>40)
{
grossSalary[i]=((hours[i]-40)*(1.5*rate[i])+(rate[i]*40)); //grosspay
baseSalary[i]=rate[i]*40; //base salary incase of overtime
overtimePay[i] = ((hours[i]-40)*(rate[i]*1.5)); //calculatingovertime pay
tax[i]=grossSalary[i]*.2; //calculating tax
netPay[i]=grossSalary[i]-tax[i]; //calculating net pay
}
else
{
grossSalary[i]=hours[i]*rate[i];
baseSalary[i]=hours[i]*rate[i];
overtimePay[i] =0;
tax[i]=grossSalary[i]*.2; //calculating tax
netPay[i]=grossSalary[i]-tax[i]; //calculating net pay
}
printf("Gross Pay: $%.2f ",grossSalary[i]);
printf("Base Pay: $%.2f ",baseSalary[i]);
printf("Overtime Pay: $%.2f ",overtimePay[i]);
printf("Taxes paid: $%.2f ",tax[i]);
printf("Net Pay: $%.2f ",netPay[i]);
}
getch();
return 0;
}
Explanation / Answer
please rate - thanks message me if any problems remember arrays pass as reference #include #include #include #include void input(double[],double[],char[][10]); void calcpay(double[],double[],double[],double[],double[]); double calctax(double); void print(double[],double[],double[],double[],double[],double[],double[],double,char[][10]); int main() {int i; double rate[5], hours[5], tax[5],baseSalary[5],overtimePay[5],grossSalary[5],netPay[5]; double total=0; char name[5][10]; input(hours,rate,name); calcpay(hours,rate,baseSalary,overtimePay,grossSalary); for(i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.