Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<iomanip>
- #include<string>
- using namespace std;
- //global variables
- const int SIZE = 100;
- const char STAT[4] = "SMH";
- int counter = 0;
- int hw[SIZE], status[SIZE], empid[SIZE], payrate[SIZE];
- string firstname[SIZE], lastname[SIZE];
- float taxnet[SIZE];
- float taxwh[SIZE];
- float overtime[SIZE];
- float gross[SIZE];
- float bracket[SIZE];
- float taxes[SIZE];
- float net[SIZE];
- float overtimepay[SIZE];
- float RegGrossPay[SIZE];
- float ravg[SIZE];
- //function prototype
- //data_entry(myFile, firstname, lastname, hw, status, empid, payrate, counter);
- void data_entry(char &);
- void payrollcalc(ofstream &);
- void data_recall(void);
- //void payrollcalc(int counter, float employeenumber[counter], float manhours[counter], float payrate[counter], float status[counter]);
- //main
- int main(){
- char usercontrol;
- //while (usercontrol != '4'){//delete
- do{
- cout << "Press 1 to enter more data press 2 to recall a data file press 4 to exit. ";
- cin >> usercontrol;
- //data entry
- if (usercontrol == '1')
- data_entry(usercontrol);
- //data recall
- else if(usercontrol == '2')
- data_recall();
- //choices: 1, 2, 4. other choice will rerun loop
- }while (usercontrol != '4');
- return 0;
- }
- //Data Entry
- void data_entry(char &usercontrol){
- ofstream myFile("employee.payroll.txt", ios::out);
- if(!myFile){
- cout << "Cannot create file!!\nProgram terminating!!\n";
- exit(0);
- }
- myFile << left << "DR. EBRAHIMI'S PAYROLL INSTITUTE\n\n";
- myFile << "FIRST NAME LAST NAME STAT SSN HW HR OTH OTP REGP GROSS TAX NET Running avg\n";
- myFile << "========== ========= ==== === == == === === ==== ===== === === ===========\n";
- do{
- cout << "Enter employees first name: ";
- cin >> firstname[counter];
- cout << "Enter employees last name: ";
- cin >> lastname[counter];
- do{
- cout << "Enter 1 for single, 2 for married, and 3 for head of household: ";
- cin >> status[counter];
- if(status[counter]>3 || status[counter]<1)
- cout << "Invalid option!\n";
- }while(status[counter]>3 || status[counter]<1);
- cout << "Enter Employee ID: ";
- cin >> empid[counter];
- cout << "Enter Number of Hours Worked: ";
- cin >> hw[counter];
- cout << "Enter Pay rate: ";
- cin >> payrate[counter];
- //payroll calculation
- //do we need to pass down the index? maybe we need, double check afterwards
- payrollcalc(myFile);
- //payrollcalc(counter, employeenumber, manhours, payrate, status);
- counter++;
- do{
- cout << "Press 1 to enter more data press 2 to recall a data file press 4 to exit. ";
- cin >> usercontrol;
- }while(usercontrol != '4' && usercontrol != '1' && usercontrol != '2');
- }while(usercontrol == '1');
- myFile.close();
- }
- //payroll calculation
- //void payrollcalc(int counter, float employeenumber[counter], float manhours[counter], float payrate[counter], float status[counter]){
- void payrollcalc(ofstream &myFile){
- if (hw[counter] > 40) {
- overtime[counter] = (float)hw[counter] - 40;
- overtimepay[counter] = (overtime[counter] * payrate[counter]) * 1.5;
- RegGrossPay[counter] = (hw[counter]-overtime[counter]) * payrate[counter];
- gross[counter] = overtimepay[counter] + RegGrossPay[counter];
- //gross[counter] = ((hw[counter] - overtime[counter]) * payrate[counter]) + ((payrate[counter] * 1.5)* overtime[counter]);
- ///overtime claculation
- }
- else {
- RegGrossPay[counter] = gross[counter] = hw[counter] * payrate[counter];
- ///no overtime calculation
- }
- if (gross[counter] > 1000){
- taxnet[counter] = .7;
- taxwh[counter] = .3;
- bracket[counter] = 3;
- }
- else if (800<gross[counter]<=1000){
- taxnet[counter] = .8;
- taxwh[counter] = .2;
- bracket[counter] =2;
- }
- else if(500<gross[counter]<=800){
- taxnet[counter]= .9;
- taxwh[counter]=.1;
- bracket[counter] = 1;
- }
- else if(gross[counter]<= 500){
- taxnet[counter] = 1;
- taxwh[counter] = 0;
- bracket[counter]= 0;
- }
- ///finds tax bracket
- if (status[counter] == 1){
- taxwh[counter] += .05;
- taxnet[counter] -= .05;
- }
- else if(status[counter] == 2){
- taxwh[counter] += 0;
- taxnet[counter] -= 0;
- }
- else if(status[counter] == 3){
- taxwh[counter] -= .05;
- taxnet[counter] += .05;
- }
- //decides marital status
- taxes[counter] = gross[counter] * taxwh[counter];
- net[counter] = taxnet[counter] * gross[counter];
- for (int a = 0; a<counter; a++){
- float sum;
- float temp = counter;
- float temp2 = 0;
- sum+=net[counter];
- temp2 = temp +1;
- ravg[counter] = sum/temp2;
- }
- //tax calc
- /*
- cout << " Your ID is " << empid[counter] << endl;
- cout << " # of hours worked " << hw[counter] << endl;
- cout << " Your Hourly rate is " << payrate[counter] << endl;
- cout << " Your Gross pay is " << gross[counter] << endl;
- cout << " Your tax bracket is " << bracket[counter] << endl;
- if (status[counter] == 1){
- cout << " You are single your tax modifier is + 5% taxes" <<endl;
- }
- else if(status[counter] == 2){
- cout << " You are married your tax modifier is 0% more taxes" <<endl;
- }
- else if(status[counter] == 3){
- cout << " You are head of household your tax modifier is - 5% taxes" <<endl;
- }
- cout << " Your tax rate is " << taxwh[counter] << endl;
- cout << " Amount of taxes " << taxes[counter] << endl;
- cout << " Your net pay is " << net[counter] << endl;
- */
- myFile << left << setw(15) << firstname[counter] << setw(15) << lastname[counter];
- myFile << setw(10) << status[counter] << setw(8) << empid[counter];
- myFile << setw(8) << hw[counter] << setw(8) << payrate[counter];
- myFile << setw(8) << overtime[counter] << setw(8) << overtimepay[counter];
- myFile << setw(8) << RegGrossPay[counter] << setw(8) << gross[counter];
- myFile << setw(8) << taxes[counter] << setw(8) << net[counter]<< setw(8) << ravg[counter] << endl;
- cout << left << "DR. EBRAHIMI'S PAYROLL INSTITUTE\n\n";
- cout << "FIRST NAME LAST NAME STAT SSN HW HR OTH OTP REGP GROSS TAX NET Running avg\n";
- cout << "========== ========= ==== === == == === === ==== ===== === === ===========\n";
- cout << left << setw(15) << firstname[counter] << setw(15) << lastname[counter];
- cout << setw(10) << status[counter] << setw(8) << empid[counter];
- cout << setw(8) << hw[counter] << setw(8) << payrate[counter];
- cout << setw(8) << overtime[counter] << setw(8) << overtimepay[counter];
- cout << setw(8) << RegGrossPay[counter] << setw(8) << gross[counter];
- cout << setw(8) << taxes[counter] << setw(10) << net[counter] << setw(10) << ravg[counter] << endl;
- ///calc out put
- //std::string empnum = std::to_string(employeenumber[counter]);
- //ofstream payroll(empnum + ".txt");
- //writeWorkerInfo(payroll[counter], employeenumber[counter], manhours[counter], payrate[counter], gross[counter], taxwh[counter], taxes[counter], net[counter], bracket[counter], status[counter]);
- ///sends up to write the file
- /// The file automatically closes when you leave the function.
- }
- /*
- void writeWorkerInfo(ofstream &stream, int employeenumber, float manhours, float payrate, float gross, float taxwh, float taxes, float net, float bracket, float status){
- stream << " Your ID is " << employeenumber << endl;
- stream << " # of hours worked " << manhours << endl;
- stream << " Your Hourly rate is " << payrate << endl;
- stream << " Your Gross pay is " << gross << endl;
- stream << " Your tax bracket is " << bracket << endl;
- if (status == 1){
- stream << " You are single your tax modifier is 5% more taxes" <<endl;
- }
- else if(status == 2){
- stream<< " You are married your tax modifier is 0% more taxes" <<endl;
- }
- else if(status == 3){
- stream << " You are head of household your tax modifier is 5% less taxes" <<endl;
- }
- stream << " Your tax rate is " << taxwh << endl;
- stream << " Amount of taxes " << taxes << endl;
- stream << " Your net pay is " << net << endl;
- ///file is writen
- }
- */
- void data_recall(){
- ifstream inputFile("employee.payroll.txt", ios::in);//not fstream dont need ios::in
- if (!inputFile){
- cout << "File does not exist!!\n";
- cout << "Program terminating!!\n";
- exit(1);//error
- }
- //file exist, first 3 line need to be removed
- string buffer;
- //reset counter
- counter = 0;
- while (getline(inputFile,buffer)){
- cout << buffer;
- }
- cout << endl;
- inputFile.close();
- /* string filename;//employeenumber[];
- cout << "Enter employee number with txt at the end";
- cin >> filename;
- cin >> employeenumber[];
- ifstream payroll;
- payroll.open(filename.c_str());
- //payroll <<
- /*
- Your ID is 1234
- # of hours worked 123
- Your Hourly rate is 15
- Your Gross pay is 2467.5
- Your tax bracket is 3
- You are head of household your tax modifier is 5% less taxes
- Your tax rate is 0.25
- Amount of taxes 616.875
- Your net pay is 1850.62
- */
- //payroll.close();
- //payroll.open(employeenumber.c_str() );
- ///I have no idea what going on here i would love soem feed back. the program apears to loop forever
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement