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
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include <fstream>
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];
char answer;
int hours[SIZE], level[SIZE];
double rate[SIZE], myGross[SIZE], myStateTax[SIZE], myFedTax[SIZE], myUnionFees[SIZE];
double myNet[SIZE];
ofstream outputFile;
outputFile.open("E:\\CIS265\\PayrollProgram.txt");
do
{
for(int idx = 0; idx < SIZE; idx++) //for loop to iterate through questions for several employees
{
cout << "Enter the following employee info." << endl;
//enter employee first name and save to array
cout << "First name: ";
cin >> fname[idx];
//enter employee middle name and save to array
cout << "Middle Initial: ";
cin >> mname[idx];
//enter employee last name and save to array
cout << "Last name: ";
cin >> lname[idx];
do //employee ID entry with input validation and save to array
{
cout << "Employee ID#: ";
cin >> id[idx];
//make sure id is six characters long
if (id[idx].size() == 6)
break;
else
cout << "Invalid employee ID#. Must be 6 characters. Try again.\n";
} while(1); //if it's not six characters long, loop the question again
do //get pay rate with input validation
{
cout << "Hourly Rate: $";
cin >> rate[idx];
//make sure pay rate is a positive number
if (rate[idx] > 0)
break;
else
cout << "Invalid pay rate. Must be > $0.00. Try again.\n ";
} while (1); //if pay rate is not a positive number, loop the question again
do //enter Level with validation
{
cout << "Employee Level (1, 2 or 3): ";
cin >> level[idx];
if (level[idx] == 1 || level[idx] == 2 || level[idx] == 3)
break;
else
cout << "Invalid Entry. Level must be 1, 2, or 3. Try again." << endl;
} while (1);//if not valid entry, loop the question again.
//if levels 1 or 2, then ask OT hours.
while (level[idx] == 1 || level[idx] == 2)
{
cout << "Overtime Hours Worked: ";
cin >> hours[idx];
if (level[idx] == 1)//if level 1, calculate hours
{
if (hours[idx] >= 0 && hours[idx] <= 20)
break;
else if (hours[idx] > 20)
{
cout << "You cannot work more than 20 overtime hours at Level 1." << endl;
cout << "Your OT hours will be calculated at 20 hours." << endl;
hours[idx] = 20;
break;
}
else
cout << "Invalid entry. Must be between 0 - 20." << endl;
}
else if (level[idx] == 2)
{
if (hours[idx] >= 0 && hours[idx] <= 15)
break;
else if (hours[idx] > 15)
{
cout << "You cannot work more than 15 overtime hours at Level 2." << endl;
cout << "Your OT hours will be calculated at 15 hours." << endl;
hours[idx] = 15;
break;
}
else
cout << "Invalid entry. Must be between 0 - 15." << endl;
}
if(level[idx] == 3)
hours[idx] = 0;
}
cout << endl << endl;
myGross[idx] = rate[idx] * 40 + (hours[idx]) * 1.5;
myStateTax[idx] = myGross[idx] * STATETAX;
myFedTax[idx] = myGross[idx] * FEDTAX;
myUnionFees[idx] = myGross[idx] * UNIONFEES;
myNet[idx] = myGross[idx] - (myStateTax[idx] + myFedTax[idx] + myUnionFees[idx]);
/*
cout << "Gross: " << myGross[idx] << endl;
cout << "State Tax: " << myStateTax[idx] << endl;
cout << "Fed Tax: " << myFedTax[idx] << endl;
cout << "Union Fees: " << myUnionFees[idx] << endl;
cout << "Ny Net: " << myNet[idx] << endl;
cout << endl;
*/
cout << "Do you have another employee to enter? (Y or N) ";
cin >> answer;
if (answer == 'Y')
break;
else
idx = SIZE;
}
} while(answer == 'Y' || answer == 'y');
cout << endl << endl;
//display entries to user
cout << "\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++) //step through the array and write each entry to the console.
{
cout << fname[idx] << " " << mname[idx] << " " << lname[idx] << " " << id[idx];
cout << " " << rate[idx] << " " << hours[idx] << " " << myGross[idx];
cout << " " << myStateTax[idx] << " " << myFedTax[idx] << " ";
cout << myUnionFees[idx] << " " << myNet[idx] << endl;
}
for(int idx = 0; idx < SIZE; idx++) //step through the array and write each entry to the output file.
{
outputFile << fname[idx] << " " << mname[idx] << " " << lname[idx] << " " << id[idx];
outputFile << " " << rate[idx] << " " << hours[idx] << " " << myGross[idx];
outputFile << " " << myStateTax[idx] << " " << myFedTax[idx] << " ";
outputFile << myUnionFees[idx] << " " << myNet[idx] << endl;
}
/*
cout << "Gross: " << myGross[idx] << endl;
cout << "State Tax: " << myStateTax[idx] << endl;
cout << "Fed Tax: " << myFedTax[idx] << endl;
cout << "Union Fees: " << myUnionFees[idx] << endl;
cout << "Ny Net: " << myNet[idx] << endl;
*/
system("PAUSE");
return EXIT_SUCCESS;
}
|