I have to write a code for payroll array but I'm having trouble defining the variables for it here is the question any help with this would be much appreciated
The program that calculates the simple weekly payroll for up to 20 employees. The app will prompt for employee name, hourly rate and number of hours worked. It will then calculate for gross pay (hourly rate * number of hours worked), withholding tax deduction (gross pay * 5%), social security deduction (gross pay * 3%), and medicare deduction (gross pay * 1%). The payroll report will show the calculation for each employee and the cumulative totals.
Example:
How many employees to process? 5
1 Enter name: John
1 Enter hourly rate: 15.75
1 Enter number of hours worked: 35
2 Enter name: Maria
2 Enter hourly rate: 20.00
2 Enter number of hours worked: 40
3 Enter name: Xian
3 Enter hourly rate: 17.25
3 Enter number of hours worked: 30
4 Enter name: Tyrone
4 Enter hourly rate: 19.25
4 Enter number of hours worked: 32
5 Enter name: Ahmed
5 Enter hourly rate: 16.50
5 Enter number of hours worked: 33
Employee rate hours Gross W/T SS Med Net
John 15.75 35 551.25 27.56 16.54 5.51 501.64
: : : : : : : :
: : : : : : : :
Ahmed 16.50 33 544.50 27.23 16.34 5.45 495.48
TOTALS nnn nnnn.nn nnnn.nn nn.nn nn.nn nnnnnn.nn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
class worker{
private:
char nameofemployee
int numberofhoursworked;
double hourly_rate;
double gross_pay;
public:
worker();
worker (double, double);
void sethours(int);
void sethourlyrate (double);
int gethours();
double getpayrate();
double getgross();
double gettax();
double getss();
double getmedicare();
double gettotal();
};
worker::worker(){
hourly_rate = 0
numberofhoursworked = 0
}
worker::worker(double h, double r){
hourly_rate = r;
numberofhoursworked = h;
}
void worker::sethours( double h){
numberofhoursworked = h;
}
void worker::sethourlyrate(double p){
hourly_rate = p;
}
int worker::gethours(){
return numberofhoursworked;
}
double worker::getpayrate(){
return hourly_rate;
}
double worker::getgross(){
double gross= (numberofhoursworked) * hourly_rate;
return gross;
}
double worker::gettax(){
double tax = (gross) * .05;
return tax;
}
double worker::getss(){
double ss = (gross) * .03;
return ss;
}
double worker::getmedicare(){
double medicare = (gross) * .01;
return medicare;
}
double worker::gettotal(){
double total = (gross) - (tax + ss+ medicare);
return total;
}
int main(int argc, char** argv) {
const int num_employees = 20;
payroll employee[num_employees];
double pay, hours, grosspay;
int i;
char choice;
for (int i = 0; i < num_employees; i++) {
cout << "enter employee #" << (i) << "rate of pay per hour: ";
cin >> pay
cout << "enter employee #" << (i) << "hours worked for the week: ";
cin >> hours;
employee[i].sethourlyrate(pay);
employee[i].numberofhoursworked(hours);
cout << "Continue? (Enter Y for yes/ Enter N for no)" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
}
else
break;
}
cout << "\n\nHere is the gross pay for each employee:" << endl;
cout << fixed << showpoint << setprecision(2);
for (int i = 0; i < NUM_EMPLOYEES; i++)
{
grossPay = employee[x].getGross();
cout << "The gross pay for employee # " << (x) << " is: " << grossPay << endl;
}
system("pause");
return 0;
}
|