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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include <fstream>
const int SIZE_A = 20; //Set array size for first and last name input
const int SIZE_B = 8; //Set array size for ID input
typedef char String_A[SIZE_A];
typedef char String_B[SIZE_B];
//prototypes
void Input(String_A[],String_A[],String_B[],double[],const int,char);
void MyGross(double[],double[],int[],const int);
void MyState(double[],double[],const double,const int);
void MyFed(double[],double[],const double,const int);
void MyUnion(double[],double[],const double,const int);
void MyNet(double[],double[],double[],double[],double[],const int);
void Output(String_A[],String_A[],String_B[],double[],int[],double[],double[],double[],double[],double[],const int);
using namespace std;
int main()
{
const double STATETAX = .05;
const double FEDTAX = .15;
const double UNIONFEES = .02;
const double OTRATE = 1.5;
const int SIZE = 5;
//string fname[SIZE], lname[SIZE], mname[SIZE], id[SIZE];
String_A fname[SIZE], lname[SIZE];
String_B id[SIZE];
char answer;
int hours[SIZE], level[SIZE], idx;
double rate[SIZE], myGross[SIZE], myStateTax[SIZE], myFedTax[SIZE], myUnionFees[SIZE];
double myNet[SIZE];
do
{
Input(fname,lname,id,rate,SIZE,answer);
MyGross(myGross,rate,hours,SIZE);
MyState(myStateTax,myGross,STATETAX,SIZE);
MyFed(myFedTax,myGross,FEDTAX,SIZE);
MyUnion(myUnionFees,myGross,UNIONFEES,SIZE);
MyNet(myNet,myGross,myStateTax,myFedTax,myUnionFees,SIZE);
Output(fname,lname,id,rate,hours,myGross,myStateTax,myFedTax,myUnionFees,myNet,SIZE);
}while(1);
cout << endl << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
/**************************************************************************
Input function to populate the arrays.
**************************************************************************/
void Input(String_A fname[],String_A lname[],String_B id[],double rate[],const int SIZE,char answer)
{
for(int idx = 0; idx < SIZE; idx++)
{
char answer;
cout << "Enter the following employee info." << endl;
cout << "First name: ";
cin >> fname[idx];
cout << "Last name: ";
cin >> lname[idx];
cout << "Employee ID#: ";
cin >> id[idx];
do
{
cout << "Hourly Rate: $";
cin >> rate[idx];
if (rate[idx] > 0)
break;
else
cout << "Invalid pay rate. Must be > $0.00. Try again.\n ";
} while (1);
cout << "Do you have another employee to enter? (Y or N) ";
cin >> answer;
if (answer == 'Y')
break;
else
idx = SIZE;
}
}
/**************************************************************************
MyGross function to calculate gross pay and populate the array.
**************************************************************************/
void MyGross(double myGross[],double rate[],int hours[],const int SIZE)
{
for(int idx = 0; idx < SIZE; idx++)
{
myGross[idx] = rate[idx] * 40 + (hours[idx]) * 1.5;
}
}
/**************************************************************************
MyState function to calculate state tax paid and populate the array.
**************************************************************************/
void MyState(double myStateTax[],double myGross[],const double STATETAX,const int SIZE)
{
for(int idx = 0; idx < SIZE; idx++)
{
myStateTax[idx] = myGross[idx] * STATETAX;
}
}
/**************************************************************************
MyFed function to calculate fed tax paid and populate the array.
**************************************************************************/
void MyFed(double myFedTax[],double myGross[],const double FEDTAX,const int SIZE)
{
for(int idx = 0; idx < SIZE; idx++)
{
myFedTax[idx] = myGross[idx] * FEDTAX;
}
}
/**************************************************************************
MyUnion function to calculate union fees paid and populate the array.
**************************************************************************/
void MyUnion(double myUnion[],double myGross[],const double UNIONFEES,const int SIZE)
{
for(int idx = 0; idx < SIZE; idx++)
{
myUnion[idx] = myGross[idx] * UNIONFEES;
}
}
/**************************************************************************
MyNet function to calculate net income and populate the array.
**************************************************************************/
void MyNet(double myNet[],double myGross[],double myStateTax[],double myFedTax[],double myUnionFees[],const int SIZE)
{
for(int idx = 0; idx < SIZE; idx++)
{
myNet[idx] = myGross[idx] - (myStateTax[idx] + myFedTax[idx] + myUnionFees[idx]);
}
}
/**************************************************************************
Output function to display the arrays.
**************************************************************************/
void Output(String_A fname[],String_A lname[],String_B id[],double rate[],int hours[],double myGross[],double myStateTax[],double myFedTax[],double myUnionFees[],double myNet[],const int SIZE)
{
cout << "\n\n\t\t\tCompany A B C" << endl;
cout << "\t\t\t= = = = = = =" << endl;
cout << "\t\t\tPay Roll Program" << endl;
cout << "======================================================================";
cout << "==========" << endl;
cout << "Name " << "Id# " << "Rate/h " << "OT hours " << "Gross ";
cout << "State Tax " << "Fed Tax " << "Union Fees " << "Net " << endl;
cout << "==== " << "=== " << "====== " << "======== " << "===== ";
cout << "========= " << "======= " << "========== " << "==== " << endl;
for(int idx = 0; idx < SIZE; idx++)
{
cout << fname[idx] << " " << lname[idx] << " " << id[idx];
cout << " " << rate[idx] << " " << hours[idx] << " " << myGross[idx];
cout << " " << myStateTax[idx] << " " << myFedTax[idx] << " ";
cout << myUnionFees[idx] << " " << myNet[idx] << endl;
}
ofstream outputFile;
outputFile.open("E:\\CIS265\\PayrollProgram.txt");
for(int idx = 0; idx < SIZE; idx++)
{
outputFile << fname[idx] << " " << lname[idx] << " " << id[idx];
outputFile << " " << rate[idx] << " " << hours[idx] << " " << myGross[idx];
outputFile << " " << myStateTax[idx] << " " << myFedTax[idx] << " ";
outputFile << myUnionFees[idx] << " " << myNet[idx] << endl;
}
}
|