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
|
#include<iostream>
#include<fstream>
using namespace std;
//function definitions
int readdata(char fname[], char lname[], long int empid[], int tothrworked[], float hrrate[], int n) {
ifstream fin("employee.txt");
n = 0;
while (fin >> fname[n] >> lname[n] >> empid[n] >> tothrworked[n] >> hrrate[n]) n++;
fin.close();
return 0;
}//read data function
void calcothours(int tothrworked[], int othrworked[], int n) {
for (int i = 0;i < n;i++) {
if (tothrworked[i] > 40) othrworked[i] = tothrworked[i] - 40;
else if (tothrworked[i] <= 40) othrworked[i] = 0;
}//end of FOR
}//calculating overtime hours
void calcreghours(int reghrworked[], int tothrworked[], int n) {
for (int i = 0;i < n;i++) {
if (tothrworked[i] > 40) reghrworked[i] = 40;
else if (tothrworked[i] <= 40) reghrworked[i] = tothrworked[i];
}//end FOR
}//calculating regular hours
void calcotpay(int othrworked[], float hrrate[], float otpay[], int n) {
for (int i = 0;i < n;i++) {
otpay[i] = (hrrate[i] * 1.5) * othrworked[i];
}//end of FOR
}//calculating overtime pay
void calcregpay(int reghrworked[], float hrrate[], float regpay[], int n) {
for (int i = 0;i < n;i++) {
regpay[i] = reghrworked[i] * hrrate[i];
}//end FOR
}//calculating regular pay
void calcgrosspay(float regpay[], float otpay[], float grosspay[], int n) {
for (int i = 0;i < n;i++) {
grosspay[i] = regpay[i] + otpay[i];
}//end FOR
}//calculating gross pay
void calctaxrate(float grosspay[], float taxrate[], int n) {
for (int i = 0;i < n;i++) {
if (grosspay[i] > 4000)taxrate[i] = 0.40;
else if (grosspay[i] > 3000 && grosspay[i] <= 3999)taxrate[i] = 0.30;
else if (grosspay[i] > 1000 && grosspay[i] <= 2999)taxrate[i] = 0.20;
else taxrate[i] = 0.10;
}//end FOR
}//calculating tax rate
void calctaxpaid(float grosspay[], float taxpaid[], float taxrate[], int n) {
for (int i = 0;i < n;i++) {
taxpaid[i] = grosspay[i] * taxrate[i];
}//end FOR
}//calculating tax paid
void calcnetpay(float grosspay[], float netpay[], float taxpaid[], int n) {
for (int i = 0;i < n;i++) {
netpay[i] = grosspay[i] - taxpaid[i];
}//end FOR
}//calculating net pay
void printdata(char fname[], char lname[], long int empid[], int tothrworked[], float hrrate[], float otpay[], float grosspay[], float taxpaid[], float netpay[], int n) {
cout << "FIRST NAME" << "\t" << "LAST NAME" << "\t" << "EMP ID" << "\t" << "HOURS" << "\t" << "RATE" << "\t" << "OT PAY" << "\t\t" << "GROSSPAY" << "\t\t" << "TAX PAID" << "\t" << "NET PAY" << "\t" << endl;
for (int i = 0;i < n;i++) {
cout << fname[i] << "\t" << lname[i] << "\t" << empid[i] << "\t" << tothrworked[i] << "\t" << hrrate[i] << "\t" << otpay[i] << "\t\t" << grosspay[i] << "\t\t\t" << taxpaid[i] << "\t\t" << netpay[i] << endl;
}//end FOR
}//print all the data
//prototyping all functions
int readdata(char[], char[], long int[], int[], float[], const int);
void calcothours(int[], int[], int);
void calcreghours(int[], int[], int);
void calcotpay(int[], float[], float[], int);
void calcregpay(int[], float[], float[], int);
void calcgrosspay(float[], float[], float[], int);
void calctaxrate(float[], float[], int);
void calctaxpaid(float[], float[], float[], int);
void calcnetpay(float[], float[], float[], int);
void printdata(char[], char[], long int[], int[], float[], float[], float[], float[], float[], int);
int main() {
const int MAXSIZE = 100;//maximum number of employees set at 100
//declaration of local variables
int n;
char fname[MAXSIZE], lname[MAXSIZE];
long int empid[MAXSIZE];
int tothrworked[MAXSIZE], othrworked[MAXSIZE], reghrworked[MAXSIZE];//types of hours worked
float hrrate[MAXSIZE];//pay rates
float regpay[MAXSIZE], otpay[MAXSIZE], grosspay[MAXSIZE], netpay[MAXSIZE];//pay totals
float taxrate[MAXSIZE], taxpaid[MAXSIZE];//taxes
//calling all functions
n = readdata(fname, lname, empid, tothrworked, hrrate, MAXSIZE);
calcothours(tothrworked, othrworked, n);
calcreghours(reghrworked, tothrworked, n);
calcotpay(othrworked, hrrate, otpay, n);
calcregpay(reghrworked, hrrate, regpay, n);
calcgrosspay(regpay, otpay, grosspay, n);
calctaxrate(grosspay, taxrate, n);
calctaxpaid(grosspay, taxpaid, taxrate, n);
calcnetpay(grosspay, netpay, taxpaid, n);
printdata(fname, lname, empid, tothrworked, hrrate, otpay, grosspay, taxpaid, netpay, n);
return 0;
}//end to MAIN
|