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
|
// Final.cpp
//Spring 2014
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <conio.h>
using namespace std;
void pay_report(string, string, ifstream, string, char, float);
void check(string, string, double&);
void wkly_pay_roll(ofstream&, string, string, char, float, float, double&, double&, double&, double&);
float low_salary_deduction(float, float, double&, double&, double&, double&);
float high_salary_deduction(float, float, double&, double&, double&);
float low_hourly_deduction(float, float, double&, double&, double&, double&);
float high_hourly_deduction(float, float, double&, double&, double&);
int main()
{
double state_tax = 0.03;
double fed_tax = 0.08;
double ss_tax = 0.02;
double net_pay = 0.00;
ifstream infile;
ofstream outfile;
string filename = "PAYMASTER.DAT";
string fname[10], lname[10];
char pay_type[10];
float pay_rate[10];
float year_to_date_gross[10];
int i = 0;
int input;
bool done = false;
while(!done)
{
infile.open("PAYMASTER.dat");
cout << "Please press enter choose from the following." << endl;
getchar();
system ("cls");
cout << "1. Would you like to run a weekly pay roll? Press 1 for yes." << endl << endl;
cout << "2. Would you like to print a pay rate/salary report? Press 2 for yes." << endl << endl;
cout << "3. Exit the program press 3" << endl << endl;
cin >> input;
getchar();
system ("cls");
switch(input)
{
case 1:
outfile.open("test.dat");
for(i = 0; i < 5; i++)
{
outfile << setprecision(2) << showpoint << fixed;
outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
}
break;
case 2:
for(i = 0; i < 5; i++)
{
pay_report(fname[i], lname[i], infile, filename, pay_type[i], pay_rate[i]);
}
break;
default:
done = true;
cout << "You have exited." << endl;
break;
}
}
if(!infile)
{
cout << "This is the inccorect file." << endl << endl;
cout << "This is the location of the file: F:/Programming Foundations 1 CH 7/FINAL PROGRAM/FINAL PROGRAM." << endl;
getchar();
system ("cls");
}
for(i = 0; i < 5; i++)
{
infile >> lname[i] >> fname[i] >> pay_type[i] >> pay_rate[i] >> year_to_date_gross[i];
}
/*outfile.open("test.dat");
for(i = 0; i < 5; i++)
{
outfile << setprecision(2) << showpoint << fixed;
//outfile << lname[i] << ',' << fname[i] << ' ' << pay_type[i] << ' ' << pay_rate[i] << ' ' << year_to_date_gross[i] << endl;
wkly_pay_roll(outfile, lname[i], fname[i], pay_type[i], pay_rate[i],year_to_date_gross[i], state_tax, fed_tax, ss_tax, net_pay);
}*/
infile.close();
outfile.close();
return 0;
}
void wkly_pay_roll(ofstream &outfile, string lname, string fname, char pay_type, float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
//float total_deduction = 0;
char ans;
int hours_worked, ot_hours, i;
for(i = 0; i < 1; i++)
{
if(pay_type == 'H')
{
cout << lname << ',' << fname << " is a hourly employee." << endl << endl;
cout << "Please enter the hours worked for this employee UP to 40 hours for this week." << endl << endl;
cin >> hours_worked;
year_to_date_gross = pay_rate * hours_worked;
cout << "Did this employee work overtime? If yes type y or n." <<endl;
cin >> ans;
getchar();
system("cls");
if(ans == 'y' || 'Y')
{
cout << "Please enter the amount of overtime hours the employee worked." << endl << endl;
cout << "Type 0 if employee did not work overtime hours." << endl;
cin >> ot_hours;
ot_hours = ot_hours *(pay_rate * 1.5);
year_to_date_gross = year_to_date_gross + ot_hours;
if(pay_rate < 30000)
{
low_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
}
else if(pay_rate > 30000)
{
high_hourly_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
}
else if(pay_type == 'S')
{
if(pay_rate < 30000)
low_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, ss_tax, net_pay);
else if(pay_rate > 30000)
high_salary_deduction(pay_rate, year_to_date_gross, state_tax, fed_tax, net_pay);
}
outfile << lname << ' ' << fname << ' ' << pay_type << ' ' << ' ' << pay_rate << ' ' << year_to_date_gross << endl;
check(fname, lname, net_pay);
//total_deduction = year_to_date_gross - net_pay;
cout << "Check is ready to print." << endl;
getchar();
system("pause");
system("cls");
outfile.close();
}
}
}
}
float low_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
state_tax = state_tax * pay_rate;
fed_tax = fed_tax * pay_rate;
ss_tax = ss_tax * pay_rate;
return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_salary_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
state_tax = state_tax * pay_rate;
fed_tax = fed_tax * pay_rate;
return net_pay = year_to_date_gross - state_tax - fed_tax;
}
float low_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& ss_tax, double& net_pay)
{
state_tax = state_tax * pay_rate;
fed_tax = fed_tax * pay_rate;
ss_tax = ss_tax * pay_rate;
return net_pay = year_to_date_gross - state_tax - fed_tax - ss_tax;
}
float high_hourly_deduction(float pay_rate, float year_to_date_gross, double& state_tax, double& fed_tax, double& net_pay)
{
state_tax = state_tax * pay_rate;
fed_tax = fed_tax * pay_rate;
return net_pay = year_to_date_gross - state_tax - fed_tax;
}
void check(string fname, string lname, double& net_pay)
{
ofstream fout;
string date;
int cents;
int dollars = (int) net_pay;
cents = (int)((net_pay - dollars) * 100);
for(int i = 0; i < 1; i++)
{
fout.open(lname.c_str());
cout << "Type in the date. (m/d/yyyy)" << endl;
cin >> date;
cout << setprecision(2) << showpoint << fixed;
fout << "12432 Somewhere St." << endl;
fout << setw(12) << left << setfill(' ') << "Russellville, AR 72802" << setw(12) << right << setfill('_') << date << setw(8) << right << setfill('_') << "Date" << endl;
fout << endl << endl;
fout << setw(7) << left << setfill('_') << "Pay" << setw(50) << left << setfill('_') << fname << ' ' << lname << " $" << setw(15) << right << setfill('_') << net_pay << endl;
fout << endl << endl;
fout << setw(10) << left << setfill('_') << dollars << "_Dollars_&_" << setw(10) << left << setw(10) << right << cents << " Cents" << endl;
fout << endl << endl;
fout << setw(10) << right << setfill('_') << left << "Bank of Foundations I" ;
fout << endl << endl << endl;
fout.close();
}
}
void pay_report(string fname, string lname, ifstream infile, string filename, char pay_type, float pay_rate)
{
infile.open(filename.c_str());
float trash;
cout << setprecision(2) << showpoint << fixed;
infile >> lname >> fname >> pay_type >> pay_rate >> trash;
cout << "Employee's Name" << setw(6)<< right << setfill(' ') << "Employee's Pay Type" << setw(6) << right << setfill(' ') << "Employee's pay rate" << endl << endl;
cout << fname << ' ' << lname << setw(6)<< right << setfill(' ') << pay_type << setw(6)<< right << setfill(' ') << pay_rate << endl << endl;
infile.close();
}
|