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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include "stdafx.h"
#include <iostream>
using namespace std;
class worker{
private:
char nameofemployee;
double numberofhoursworked;
double hourly_rate;
double gross_pay;
double gross, ss, medicare, tax;
public:
worker();
worker(double, double);
void sethours(double);
void sethourlyrate(double);
void setname(int);
double 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;
}
void worker::setname(int) {
nameofemployee = 'n';
}
double 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()
{
const int num_employees = 20;
worker employee[num_employees];
double pay, hours, grosspay, social_s, medi, tax, subtotal;
int i;
char choice, name;
for (int i = 0; i < num_employees; i++) {
cout << (i + 1) << "enter employee name";
cin >> name;
cout << (i+1) << "enter employee rate of pay per hour: ";
cin >> pay;
cout << (i+1) << "enter employee hours worked for the week: ";
cin >> hours;
employee[i].setname(name);
employee[i].sethourlyrate(pay);
employee[i].sethours(hours);
cout << "Continue? (Enter Y for yes/ Enter N for no)" << endl;
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
}
else
break;
}
for (int i = 0; i < num_employees; i++)
{
grosspay = employee[i].getgross();
social_s = (grosspay) * .05;
social_s = employee[i].getss();
medi = employee[i].getmedicare();
tax = employee[i].gettax();
subtotal = employee[i].gettotal();
cout << "The gross pay for employee # " << (i + 1) << " is: " << grosspay << endl;
cout << "The social security for employee # " << (i + 1) << " is: " << social_s << endl;
cout << "The medicare for employee # " << (i + 1) << " is: " << medi << endl;
cout << "The tax for employee # " << (i + 1) << " is: " << tax << endl;
cout << "The subtotal for employee # " << (i + 1) << " is: " << subtotal << endl;
}
system("pause");
return 0;
}
|