Sequential file data to function

I need to read an external sequential file then use that data in a functions that will calculate taxes, dues, etc. The data will be outputted to a new external file.

I think I can get my program to read the external file but I am not sure how to input it to a function ( getInput )

I've included my code but I really need to know what I should be looking for in my book. What am I trying to do?

btw, I cut the middle out of my program so it'll fit.

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

//  Date of Submission: 10Oct2012
//  Date due:16October2012
//  CISC 192 C/C++ Programming
//  C++ Programming Project 3
//  Our client has several employees, therefore, program must prompt keyboard operator to determine whether there is another employee to be processed, if not, display results (see output section below) and terminate program; otherwise prompt user and accept input data for next employee.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;




class Employee {
public:
    
    void getInput( string    empLastName[]  , char payrollType[], double hoursWorked[],
                  double payRate[], int  unionCode[]  , int &count )
    {
        count = 0;
        char moreToAdd;
        
        // while loop will continue to loop so user can add all of
        // the employees at once.
        do
        {
            // empLastName are from 100-800 only. Validate employee number
            cout << "Enter Employee ID from 100-800: ";
            cin >> empLastName[count];
            while( empLastName[count]<100 || empLastName[count]>800 )
            {
                cout << "Invalid Input\n";
                cout << "Enter Employee ID from 100-800: ";
                cin >> empLastName[count];
            }
            
            // payrollType is 'h' or 'H' Validate payroll type.
            cout << "Enter Payroll type(h or H): ";
            cin >> payrollType[count];
            while( payrollType[count]!='h' && payrollType[count]!='H' )
            {
                cout << "Invalid Input\n";
                cout << "Enter employee's payroll type(h or H): ";
                cin >> payrollType[count];
            }
            
            // Validation of hours worked. They must be between 0-60.0.
            cout << "Enter the number of hours worked(0-60): ";
            cin >> hoursWorked[count];
            while( hoursWorked[count]< 0 || hoursWorked[count]>60.0 )
            {
                cout << "Invalid Input\n";
                cout << "Enter the number of hours worked(0-60): ";
                cin >> hoursWorked[count];
            }
            
            // Validation of employee's pay rate.
            cout << "Enter pay rate(8.5-45): ";
            cin >> payRate[count];
            while( payRate[count]<8.50 || payRate[count]>45.00 )
            {
                cout << "Invalid Input\n";
                cout << "Enter pay rate(8.5-45): ";
                cin >> payRate[count];
            }
            
            // Validation of employee's union code.
            cout << "Enter union code(1,2,3): ";
            cin >> unionCode[count];
            while( unionCode[count] !=1 &&
                  unionCode[count] !=2 &&
                  unionCode[count] !=3 )
            {
                cout << "Invalid input\n";
                cout << "Enter union code(1,2,3): ";
                cin >> unionCode[count];
            }
            
            //  counters inside of while loop.
            count++;
            
            cout << "Add more employees(y/n)? ";
            cin >> moreToAdd;
            cout << "\n";
            
        }while( moreToAdd=='y' || moreToAdd=='Y'); // end while loop.
    } // End getInput function.

    // getInput recieves input from the users
    
    
    void doCalculations(
                        double hoursWorked[], double payRate[], int  unionCode[]  ,
                        double regularPay[],  double overtimePay[], double grossPay[],
                        double stateTax[],    double federalTax[],
                        double unionDues[],   double netPay[],
                        int count )
    {
        for( int i=0; i<count; i++ )
        {
            if( hoursWorked[i] > 40 )
            {
                regularPay[i]  = payRate[i] * 40;
                overtimePay[i] = (1.5*payRate[i]) * (hoursWorked[i] - 40.0);
            }
            else
            {
                regularPay[i]   = payRate[i] * hoursWorked[i];
                overtimePay[i] = 0;
            }
            grossPay[i] = regularPay[i] + overtimePay[i];
            
            // State and Federal tax
            if( grossPay[i] < 500 )
            {
                stateTax[i] = 0;
                federalTax[i] = 0;
            }
            else if( grossPay[i]<1000 )
            {
                stateTax[i]    = grossPay[i] * .03;
                federalTax[i]  = grossPay[i] * .05;
            }
            else
            {
                stateTax[i]   = grossPay[i] * .05;
                federalTax[i] = grossPay[i] * .07;
            }
            if( unionCode[i] == 1 ) unionDues[i] = 15;
            else if( unionCode[i] == 2 ) unionDues[i] = 25;
            else                         unionDues[i] = 35;
            
            netPay[i] = grossPay[i] - stateTax[i] - federalTax[i] - unionDues[i];
        }
    } //  End doCalculations function
    
    
        {
            totalGross += grossPay[i];
            totalNet   += netPay[i];
            
            if( grossPay[i]>grossPay[maxGrossIndex] ) maxGrossIndex = i;
            if( grossPay[i]<grossPay[minGrossIndex] ) minGrossIndex = i;
        }
        
        cout << "Total Employees Entered: " << count      << endl;
        cout << "Total Gross Pay: $"        << totalGross << endl;
        cout << "Total Net Pay: $"          << totalNet   << endl;
        
        cout << "Employee with highest gross pay ID: "  << empLastName[maxGrossIndex] << endl;
        cout << "Highest gross pay: $"                  << grossPay[maxGrossIndex] << endl;
        
        cout << "Employee with lowest  gross pay ID: "  << empLastName[minGrossIndex] << endl;
        cout << "Lowest gross pay: $"                   << grossPay[minGrossIndex] << endl;
        
        cout << "Average gross pay: $"  << totalGross/count << endl;
        cout << "Average net pay: $"    << totalNet/count   << endl;
    }
    

    
    
};


void outputLine ( string    empLastName[]  , char payrollType[], double hoursWorked[],
                 double payRate[], int  unionCode[]  );


int main(int argc, const char * argv[])
{
    //Read the supplied textfile
    ifstream inClientFile("employee_data_in.txt" , ios::in );
    // exit if program isf ifstream cannot open file
    if ( !inClientFile )
    {
        cerr << "File could not be opened" << endl;
        exit(1);
        }
    }// end if

while ( inClientFile >> lastName >> payrollType >> hoursWorked >> payRate >> unionCode ) {
    getInput ( lastName , payrollType, hoursWorked, payRate, unionCode )
}
    


    
    
    
    Employee worker;
    //  number of items in the array
    int count = 0;
    
    // Declare Array Variables for input by user
    char   empLastName[SIZE];
    char   payrollType[SIZE] ;
    double hoursWorked[SIZE];
    double payRate[SIZE];
    int    unionCode[SIZE];
    
    // Declare Array Variables calculated
    double regularPay[SIZE];
    double overtimePay[SIZE];
    double grossPay[SIZE];
    double stateTax[SIZE];
    double federalTax[SIZE];
    double unionDues[SIZE];
    double netPay[SIZE];
    
    worker.getInput( empLastName, payrollType, hoursWorked, payRate, unionCode, count );
    
    worker.doCalculations( hoursWorked, payRate, unionCode,
                   regularPay, overtimePay, grossPay,    stateTax,
                   federalTax, unionDues,   netPay,
                   count );
    
    worker.displayEmployeeResults(
                           empLastName, payrollType, hoursWorked, payRate, unionCode,
                           regularPay, overtimePay, grossPay,    stateTax,
                           federalTax, unionDues,   netPay,
                           count );
    
    worker.displayPayrollSummaryResults( empLastName, grossPay, netPay, count );
    
    return 0;
}
Topic archived. No new replies allowed.