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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int SIZE = 10;
double CalculateGrossPay(double hWorked, double hRate, double grossPayArray[], double oTime, double cont401k, double insDeduct, double choice);
void CalculateTaxDeductions(double grossPayArray[], double& FIT, double& FICA, double& SIT, double& FMED);
void CalculateNetPay(double netPayArray[], double grossPayArray[], double& FIT, double& FICA, double& FMED, double& SIT, double& insDeduct);
//Function prototypes
void ReadInputData(ifstream& input, ofstream& output, double empNameArray[], double grossPayArray[], double netPayArray[], string& empId, double& hWorked, double& hRate, char& choice,
char& employeeType, double& insDeduct, double& cont401k);
//Prints out the employee's pay stub
void WriteOutputData(ofstream& output, string empId, double empNameArray[], double grossPayArray[], double FIT, double FICA, double FMED,
double SIT, double insDeduct, double cont401k, double netPayArray[]);
int HIGHEST_GROSSPAY_SALARY(double grossPayArray[], int Counter);
int HIGHEST_NETPAY_SALARY(double netPayArray[], int Counter);
string Determine_HIGHEST_GROSSPAY_SALARY(double grossPay);
string Determine_HIGHEST_NETPAY_SALARY(double netPay);
//Tax Rate by Code...
const double FICArate = 0.062;
const double FMEDrate = 0.0145;
const double SITrate = 0.05;
const double FITrate = 0;
//Paycode by rate...
const double Mrate = 27.50;
const double Crate = 19.50;
const double Lrate = 10.35;
//Insurance Code
const double Acode = 25.00;
const double Bcode = 15.00;
const double Ccode = 0.00;
//Tax Bracket for FIT
const double Bracket1 = 0.125;
const double Bracket2 = 0.22;
const double Bracket3 = 0.2935;
void main()
{
//Variable declaration
double empName = 0;
string empId = "";
double hWorked = 0;
double hRate = 0;
double oTime = 0;
double grossPay = 0;
double cont401k = 0;
double insDeduct = 0;
double FIT = 0;
double FICA = 0;
double SIT = 0;
double FMED = 0;
double netPay = 0.0;
char employeeType;
char choice = 0;
ifstream input;
ofstream output;
double empNameArray[SIZE] = { 0.00 };
double grossPayArray[SIZE] = { 0.00 };
double netPayArray[SIZE] = { 0.00 };
char inFile[51];
char outFile[51];
cout << "Enter the infile Name" << endl;
cin >> inFile;
cout << endl;
input.open(inFile); //Open the input file.
if (!input)
{
cout << "Cannot open input file."
<< "Program terminates!" << endl;
return;
}
cout << "Enter the outfile file name: ";
cin >> outFile;
cout << endl;
output.open(outFile);//Open the output file.
CalculateGrossPay(hWorked, hRate, grossPayArray, oTime, cont401k, insDeduct, choice);
CalculateTaxDeductions(grossPayArray, FIT, FICA, SIT, FMED);
CalculateNetPay(netPayArray, grossPayArray, FIT, FICA, FMED, SIT, insDeduct);
ReadInputData(input, output, empNameArray, grossPayArray, netPayArray, empId, hWorked, hRate, choice,employeeType, insDeduct, cont401k);
WriteOutputData(output, empId, empNameArray, grossPayArray, FIT, FICA, FMED, SIT, insDeduct, cont401k, netPayArray);
}
void ReadInputData(ifstream input, double empNameArray, double grossPayArray, double netPayArray, string empId, double hWorked, double hRate, char choice, char employeeType, double insDeduct, double cont401k)
{
ifstream input;
input.open("InputData.txt");
input.ignore(1000, '\n');
int counter = 0;
input >> empNameArray[counter];
input >> grossPayArray[counter];
input >> netPayArray[counter];
while (input && (counter < SIZE))
{
counter++;
input >> empNameArray[counter];
input >> grossPayArray[counter];
input >> netPayArray[counter];
input >> empId;
input >> hWorked;
input >> hRate;
input >> choice;
}
switch (employeeType)
{
//Manager Hourly Pay Rate
case 'm':
case 'M':
hRate = Mrate;
break;
//Contrator Hourly Pay Rate
case 'c':
case 'C':
hRate = Crate;
break;
//Level Hourly Pay Rate
case 'l':
case 'L':
hRate = Lrate;
break;
default:
hRate = Lrate;
}
if (choice == 'A')
insDeduct = 25.00;
if (choice == 'B')
insDeduct = 15.00;
if (choice == 'C')
insDeduct = 0.00;
}
double CalculateGrossPay(double hWorked, double hRate, double grossPay, double oTime, double cont401k)
{
if (hWorked > 40 && hWorked <= 48)
{
grossPay = (40 * hRate) + (hWorked - 40)*(hRate*1.5) - cont401k;
}
if (hWorked > 48)
{
grossPay = 40 * hRate + 8 * 1.5 * hRate + (hWorked - 48) * 2.0 * hRate - cont401k;
}
return grossPay;
}
double CalculateTaxDeductions(double& grossPay, double& FIT, double& FICA, double& SIT, double& FMED, double& insDeduct, char choice)
{
if (grossPay > 0 && grossPay < 350.00)
FIT = (grossPay * Bracket1);
if (grossPay > 350.00 && grossPay < 1000.00)
FIT = (grossPay * Bracket2);
if (grossPay > 1000.00)
FIT = (grossPay * Bracket3);
else
FICA = FICArate * grossPay;
FMED = FMEDrate * grossPay;
SIT = SITrate * grossPay;
insDeduct = choice - grossPay;
return insDeduct;
}
void CalculateNetPay(double& netPay, double& grossPay, double& FIT, double& FICA, double& FMED, double& SIT, double& insDeduct)
{
netPay = grossPay - FIT - FICA - FMED - SIT - insDeduct;
}
void WriteOutputData(ofstream& outFile, string empId, string empName, double grossPay, double FIT, double FICA, double FMED,
double SIT, double insDeduct, double cont401k, double netPay)
{
ofstream outFile;
outFile.open("output.txt");
for (int i = 0; i < SIZE; i++)
{
outFile << "----------------------------------------------------------" << endl;
outFile << "ID Name Gross FIT FMED FICA SIT 401k Ins Net" << endl << endl;
outFile << setw(6) << empId;
outFile << fixed << showpoint;
outFile << setw(10) << setprecision(2) << empName
<< setw(9) << setprecision(2) << grossPay
<< setw(7) << setprecision(2) << FIT
<< setw(6) << setprecision(2) << FICA
<< setw(6) << setprecision(2) << FMED
<< setw(6) << setprecision(2) << SIT
<< setw(5) << setprecision(2) << cont401k
<< setw(8) << setprecision(2) << insDeduct
<< setw(9) << setprecision(2) << netPay
<< endl;
outFile << endl;
outFile << "--------------------------------------------------" << endl;
}
string Determine_HIGHEST_GROSSPAY_SALARY(double grossPay);
{
string HighestGrossPaySalary = "";
if (grossPay > 10, 000)
{
HighestGrossPaySalary = "";
}
else if ((grossPay > 0) && (grossPay < 10, 000))
{
HighestGrossPaySalary = "";
}
else
{
HighestGrossPaySalary = "";
}
return HighestGrossPaySalary;
}
string Determine_HIGHEST_NETPAY_SALARY(double netPay);
{
string HighestNetPaySalary = "";
if (grossPay > 10, 000)
{
HighestNetPaySalary = "";
}
else if ((grossPay > 0) && (grossPay < 10, 000))
{
HighestNetPaySalary = "";
}
else
{
HighestNetPaySalary = "";
}
return HighestNetPaySalary;
}
|