Problem with sorting function

I am having trouble sorting the netpays in a payroll program. My prof emailed me a sample and I tried to incorporate into my code, but it still will not compile. Can you guys give me some pointers. Below is the sample he sent me, and my code.

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

// HIS SAMPLE



void employeeSwap(Employee x[], int i, int j){

Employee temp;

temp=x[i];

x[i]=x[j];

x[j]=temp;

}

 

// sorts the employees by netpay

void sortByNetPayAscending(Employee employees[], int numEmployees){

 

// bubble sort netpay, keeping the data indexed

for(int i=1; i<numEmployees; i++){

for(int j=0; j<numEmployees-i;j++){

if(employees[j].getNetPay() > employees[j+1].getNetPay()){

employeeSwap(employees,j,j+1);

}

}

}

}
======

// loops the payroll program the desired number of times, filling the starting arrays

while(fin>>employeeId>>firstName>>lastName>>maritalStatus>>hoursWorked>>wage>>salaried){

 

employees[numEmployees].setID(employeeId);

employees[numEmployees].setFirstName(firstName);

employees[numEmployees].setLastName(lastName);

employees[numEmployees].setMaritalStatus(maritalStatus);

employees[numEmployees].setHoursWorked(hoursWorked);

employees[numEmployees].setHourlyRate(wage);

 

if(salaried == 'S' || salaried == 's'){

SalariedEmployee e;

 

e.setID(employeeId);

e.setFirstName(firstName);

e.setLastName(lastName);

e.setMaritalStatus(maritalStatus);

e.setHoursWorked(hoursWorked);

e.setWage(wage);

employees[numEmployees] = e;

}

 
=======


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
//MY CODE, his sample incorporated.

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

class payroll {
ifstream fin;
public: string lastname, firstName, lastName; 
char ms,maritalStatus,salaried, paystatus;
int employeeid;
float taxrate;
double wage, hoursWorked, employeeId, hoursworked, overtimehours, regularhours, hourlyrate, regularpay, minnp, maxnp, taxamount, netpay, grosspay, overtimepay, yearlysalary;
double findnetpay(), maxnet(double, int), minnet(double, int);
double findgrosspayhourly();
double findgrosspaysalaried();
void settingthevariables(char[], int, char, char, double, double, double);

void printheaders();
void printdata();
void findtaxamount();
void printminmax(double, double);
payroll();
~payroll();
};



payroll::payroll() {
fin.open("2252011.in"); }
payroll::~payroll() {
fin.close();  }



class Employee{
void employeeSwap(Employee x[], int i, int j);
void sortByNetPayAscending();
void getNetpay();
double x[],employees[];

}

void Employee::employeeSwap(Employee x[], int i, int j){
    Employee temp;
         temp=x[i];
         x[i]=x[j];
         x[j]=temp; }// sorts the employees by netpay

void sortByNetPayAscending(Employee employees[], int numEmployees){
     
     for(int i=1; i<numEmployees; i++){
             for(int j=0; j<numEmployees-i;j++){
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                                 employeeSwap(employees,j,j+1); }}}// bubble sort netpay, keeping the data indexed







void payroll::settingthevariables(char alastname[], int aemployeeid, char ams, 
char apaystatus, double ahoursworked, double ahourlyrate, double ayearlysalary) {
     lastname = alastname;
     employeeid = aemployeeid;
     ms = ams;
     paystatus = apaystatus;
     hoursworked = ahoursworked;
     hourlyrate = ahourlyrate;
     yearlysalary=ayearlysalary;
}
   
void payroll::findtaxamount() {
     taxrate = .30;
     taxamount = grosspay * taxrate;
}// findtaxamount

double payroll::findgrosspayhourly() {
        if (hoursworked > 40 ) {
           overtimehours = hoursworked - 40;
           regularpay = 40 * hourlyrate;
           overtimepay = 1.5* hourlyrate * overtimehours;
           grosspay = overtimepay + regularpay  ; }
        else {
            grosspay = hoursworked * hourlyrate;
            regularpay = grosspay; }
            return grosspay; }

double payroll::findgrosspaysalaried() {
        regularpay = yearlysalary/52; 
        overtimehours = hoursworked - 40; 
        grosspay = regularpay;
        if (hoursworked > 0) {
        overtimehours = hoursworked - 40;
           overtimepay = 1.5* overtimehours * (regularpay/40);
           grosspay = regularpay + overtimepay;
return grosspay;
        }// If
};//findgrosspay

double payroll::findnetpay()  {
     netpay = grosspay - taxamount;
return netpay;
}

double payroll::minnet(double minnp, int i) {
     if (i == 0) {minnp = 10000000;}
     if (netpay < minnp) {minnp = netpay;}
return minnp;
} 

double payroll::maxnet(double maxnp, int i) {
     if (i == 0) {maxnp = 0;}
     if (netpay > maxnp) {maxnp = netpay;}
return maxnp;
} 

void sortdata(string lastname[], double overtimepay[], double taxamount[], double netpay[] ){

     int i,j;   
     const int n = 100;
     double *anetpay[n];
     double *aovertimepay[n];
     double *ataxamount[n];
     string *alastname[n];  
     double *temp, *tempb, *tempc; 
     string *tempa; 
     int sorted = 0; 

      for( i = 0; i < n; i++ ){

         alastname[i] = lastname + i; 
         aovertimepay[i] = overtimepay + i;
         ataxamount[i] = taxamount +i;
         anetpay[i] = netpay + i; } //for
    
 while (!sorted){
         sorted = 1;
   
     for( j = 0; j < n -1; j++ ){  
        if ( *anetpay[j] > *anetpay[j+1] ){ 

         temp = anetpay[j];
         anetpay[j] = anetpay[j+1];
         anetpay[j+1] = temp;
         
         tempa = alastname[j];
         alastname[j] = alastname[j+1];
         alastname[j+1] = tempa;  
         
         tempb = aovertimepay[j];
         aovertimepay[j] = aovertimepay[j+1];
         aovertimepay[j+1] = tempb; 
         
         tempc = ataxamount[j];
         ataxamount[j] = ataxamount[j+1];
         ataxamount[j+1] = tempc; sorted = 0;
          
              }//if
         }//for
 }//while
}//sort



void payroll::printheaders(){
     
 
    cout << "------------------------------------------------------------------------------" << endl;
    cout << "LAST NAME      OT PAY         TAX            NETPAY"   << endl;
    cout << "-------------------------------------------------------------------------------" << endl;}

void payroll::printdata()    {

 	 cout<<setw(15)<<left<<lastname;
   cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
 	 cout<<setw(15)<<overtimepay<<setw(15)<<taxamount<<setw(15)<<netpay<<endl; }
      


void payroll::printminmax(double minnp, double maxnp) {
     cout<<endl<<"The Max. NETPAY is $"<<maxnp<<endl;
     cout<<"The Min. NETPAY is $"<<minnp<<endl;
}

int main() {
   const int MAXSIZE = 100;  
   
    string  lastname[MAXSIZE]; 
    double overtimepay[MAXSIZE],taxamount[MAXSIZE], netpay[MAXSIZE]; 
   
    
    payroll employee[6];
    payroll report;
    payroll settingthevariables;
    payroll findgrosspay;
    payroll findtaxamount ;          
    payroll findnetpay ;          
    payroll minnet;          
    payroll maxnet; 
    char alastname[14], ams, apaystatus;
    int aemployeeid,n, i=0;
    double ahoursworked, ayearlysalary, ahourlyrate, minnp, maxnp, ataxamount,  anetpay, 
    aovertimepay;
    
    report.printheaders();
    
    ifstream fin;
    fin.open("2252011.in");
    
    
while(fin>>employeeId>>firstName>>lastName>>maritalStatus>>hoursWorked>>wage>>salaried){

        employees[numEmployees].setID(employeeId);
        employees[numEmployees].setFirstName(firstName);
        employees[numEmployees].setLastName(lastName);
        employees[numEmployees].setMaritalStatus(maritalStatus);
        employees[numEmployees].setHoursWorked(hoursWorked);
        employees[numEmployees].setHourlyRate(wage);
        
if(salaried == 'S' || salaried == 's'){

            SalariedEmployee e;
                 e.setID(employeeId);
                 e.setFirstName(firstName);
                 e.setLastName(lastName);
                 e.setMaritalStatus(maritalStatus);
                 e.setHoursWorked(hoursWorked);
                 e.setWage(wage);
                 employees[numEmployees] = e;
}// loops the payroll program the desired number of times, filling the starting arrays
    
employees[numEmployees].printdata();
report.printminmax(minnp, maxnp);
   
     fin.close();    
     system ("pause");}
} 

What's the compilation error?

I note that you have a '}' after your final statement, putting all that last section into the while loop.
Last edited on
The first error is on line 45 two or more data types in declaration of `employeeSwap' " . i am still trying to figure this one out
You might find these compiler errors a little easier to fix. It points out the line and often the actual first bad character in the line.


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
bad.cpp:41:8: error: field has incomplete type 'double []'
double x[],employees[];
       ^
bad.cpp:41:12: error: field has incomplete type 'double []'
double x[],employees[];
           ^
bad.cpp:43:2: error: expected ';' after class
}
 ^
 ;
bad.cpp:46:14: error: no matching constructor for initialization of
      'class Employee'
    Employee temp;
             ^
bad.cpp:48:14: error: no viable overloaded '='
         x[i]=x[j];
         ~~~~^~~~~
bad.cpp:55:38: error: no member named 'getNetPay' in 'class Employee'; did you
      mean 'getNetpay'?
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                                     ^~~~~~~~~
                                     getNetpay
bad.cpp:40:6: note: 'getNetpay' declared here
void getNetpay();
     ^
bad.cpp:55:67: error: no member named 'getNetPay' in 'class Employee'; did you
      mean 'getNetpay'?
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                                                                  ^~~~~~~~~
                                                                  getNetpay
bad.cpp:40:6: note: 'getNetpay' declared here
void getNetpay();
     ^
bad.cpp:55:50: error: invalid operands to binary expression ('void' and 'void')
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                        ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
bad.cpp:56:34: error: use of undeclared identifier 'employeeSwap'
                                 employeeSwap(employees,j,j+1); }}}// ...
                                 ^
bad.cpp:64:15: error: definition or redeclaration of 'settingthevariables' not
      allowed inside a function
void payroll::settingthevariables(char alastname[], int aemployeeid, char ams, 
     ~~~~~~~~~^
bad.cpp:65:80: error: expected ';' at end of declaration
  ...double ahoursworked, double ahourlyrate, double ayearlysalary) {
                                                                   ^
                                                                   ;
bad.cpp:103:17: error: definition or redeclaration of 'findnetpay' not allowed
      inside a function
double payroll::findnetpay()  {
       ~~~~~~~~~^
bad.cpp:103:29: error: expected ';' at end of declaration
double payroll::findnetpay()  {
                            ^
                            ;
bad.cpp:240:3: error: expected '}'
} 
  ^
16 diagnostics generated.

you are missing a ; in line 43 (closing the declaration of the class).
Please be consistent with your indentation
Thanks guys.

I have amended to the below and recieve an erro on line 250 no match for 'operator=' in 'employees[numEmployees] = e' how could I define the operator =?


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
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

class payroll {
ifstream fin;
public: string lastname, firstName, lastName; 
char ms,maritalStatus,salaried, paystatus;
int employeeid;
float taxrate;
double wage, hoursWorked, employeeId, hoursworked, overtimehours, regularhours, hourlyrate, regularpay, minnp, maxnp, taxamount, netpay, grosspay, overtimepay, yearlysalary;
double findnetpay(), maxnet(double, int), minnet(double, int);
double findgrosspayhourly();
double findgrosspaysalaried();
void settingthevariables(char[], int, char, char, double, double, double);

void printheaders();
void printdata();
void findtaxamount();
void printminmax(double, double);
payroll();
~payroll();
};



payroll::payroll() {
fin.open("2252011.in"); }
payroll::~payroll() {
fin.close();  }



class Employee{
public:
void employeeSwap(Employee x[], int i, int j);
void sortByNetPayAscending();
double getNetPay();
double x[],employees[];
double setID(double);
double setFirstName(string);
double setLastName(string);
double setMaritalStatus(char);
double setHoursWorked(double);
double setHourlyRate(double);
void printdata();
Employee();
~Employee();
};



class SalariedEmployee{
public:
void employeeSwap(Employee x[], int i, int j);
void sortByNetPayAscending();
double getNetPay();
double x[],employees[];
double setID(double);
double setFirstName(string);
double setLastName(string);
double setMaritalStatus(char);
double setHoursWorked(double);
double setWage(double);
SalariedEmployee();
~SalariedEmployee();
};

void Employee::employeeSwap(Employee x[], int i, int j){
    Employee temp;
         temp=x[i];
         x[i]=x[j];
         x[j]=temp; }// sorts the employees by netpay

void sortByNetPayAscending(Employee employees[], int numEmployees){
     
     for(int i=1; i<numEmployees; i++){
             for(int j=0; j<numEmployees-i;j++){
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                                 employees[j].employeeSwap(employees,j,j+1); }}}// bubble sort netpay, keeping the data indexed
}   
void payroll::findtaxamount() {
     taxrate = .30;
     taxamount = grosspay * taxrate;
}// findtaxamount

double payroll::findgrosspayhourly() {
        if (hoursworked > 40 ) {
           overtimehours = hoursworked - 40;
           regularpay = 40 * hourlyrate;
           overtimepay = 1.5* hourlyrate * overtimehours;
           grosspay = overtimepay + regularpay  ; }
        else {
            grosspay = hoursworked * hourlyrate;
            regularpay = grosspay; }
            return grosspay; }

double payroll::findgrosspaysalaried() {
        regularpay = yearlysalary/52; 
        overtimehours = hoursworked - 40; 
        grosspay = regularpay;
        if (hoursworked > 0) {
        overtimehours = hoursworked - 40;
           overtimepay = 1.5* overtimehours * (regularpay/40);
           grosspay = regularpay + overtimepay;
return grosspay;
        }// If
};//findgrosspay

double payroll::findnetpay()  {
     netpay = grosspay - taxamount;
return netpay;
}

double payroll::minnet(double minnp, int i) {
     if (i == 0) {minnp = 10000000;}
     if (netpay < minnp) {minnp = netpay;}
return minnp;
} 

double payroll::maxnet(double maxnp, int i) {
     if (i == 0) {maxnp = 0;}
     if (netpay > maxnp) {maxnp = netpay;}
return maxnp;
} 

void sortdata(string lastname[], double overtimepay[], double taxamount[], double netpay[] ){

     int i,j;   
     const int n = 100;
     double *anetpay[n];
     double *aovertimepay[n];
     double *ataxamount[n];
     string *alastname[n];  
     double *temp, *tempb, *tempc; 
     string *tempa; 
     int sorted = 0; 

      for( i = 0; i < n; i++ ){

         alastname[i] = lastname + i; 
         aovertimepay[i] = overtimepay + i;
         ataxamount[i] = taxamount +i;
         anetpay[i] = netpay + i; } //for
    
 while (!sorted){
         sorted = 1;
   
     for( j = 0; j < n -1; j++ ){  
        if ( *anetpay[j] > *anetpay[j+1] ){ 

         temp = anetpay[j];
         anetpay[j] = anetpay[j+1];
         anetpay[j+1] = temp;
         
         tempa = alastname[j];
         alastname[j] = alastname[j+1];
         alastname[j+1] = tempa;  
         
         tempb = aovertimepay[j];
         aovertimepay[j] = aovertimepay[j+1];
         aovertimepay[j+1] = tempb; 
         
         tempc = ataxamount[j];
         ataxamount[j] = ataxamount[j+1];
         ataxamount[j+1] = tempc; sorted = 0;
          
              }//if
         }//for
 }//while
}//sort



void payroll::printheaders(){
     
 
    cout << "------------------------------------------------------------------------------" << endl;
    cout << "LAST NAME      OT PAY         TAX            NETPAY"   << endl;
    cout << "-------------------------------------------------------------------------------" << endl;}

void payroll::printdata()    {

 	 cout<<setw(15)<<left<<lastname;
   cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
 	 cout<<setw(15)<<overtimepay<<setw(15)<<taxamount<<setw(15)<<netpay<<endl; }
      


void payroll::printminmax(double minnp, double maxnp) {
     cout<<endl<<"The Max. NETPAY is $"<<maxnp<<endl;
     cout<<"The Min. NETPAY is $"<<minnp<<endl;
}

int main() {
   const int MAXSIZE = 100;  
   
    string  lastname[MAXSIZE]; 
    double overtimepay[MAXSIZE],taxamount[MAXSIZE], netpay[MAXSIZE]; 
   
    Employee employees[6];
    int numEmployees;
    payroll employee[6];
    payroll report;
    payroll settingthevariables;
    payroll findgrosspay;
    payroll findtaxamount ;          
    payroll findnetpay ;          
    payroll minnet;          
    payroll maxnet; 
    char alastname[14], ams, apaystatus;
    int aemployeeid,n, i=0;
    string firstName, lastName; 
    char maritalStatus,salaried;
    double employeeId, hoursWorked,wage,  ahoursworked, ayearlysalary, ahourlyrate, minnp, maxnp, ataxamount,  anetpay, 
    aovertimepay;
   
    report.printheaders();
    
    ifstream fin;
    fin.open("2252011.in");
    
    
while(fin>>employeeId>>firstName>>lastName>>maritalStatus>>hoursWorked>>wage>>salaried){

        employees[numEmployees].setID(employeeId);
        employees[numEmployees].setFirstName(firstName);
        employees[numEmployees].setLastName(lastName);
        employees[numEmployees].setMaritalStatus(maritalStatus);
        employees[numEmployees].setHoursWorked(hoursWorked);
        employees[numEmployees].setHourlyRate(wage);
        
if(salaried == 'S' || salaried == 's'){

            SalariedEmployee e;
                 e.setID(employeeId);
                 e.setFirstName(firstName);
                 e.setLastName(lastName);
                 e.setMaritalStatus(maritalStatus);
                 e.setHoursWorked(hoursWorked);
                 e.setWage(wage);
                 employees[numEmployees] = e;
}// loops the payroll program the desired number of times, filling the starting arrays
}
employees[numEmployees].printdata();
report.printminmax(minnp, maxnp);
   
     fin.close();    
     system ("pause");
} 
Ok, I have updated my code to the below, but I get a "expected constructor/destructor" error at the line "sortdata(employee,6);" Is the system saying I will need to build out another constructor for sortdata?

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
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

class payroll {
ifstream fin;
public: string lastname, firstName, lastName; 
char ms,maritalStatus,salaried, paystatus;
int employeeid;
float taxrate;
double wage, hoursWorked, employeeId, hoursworked, overtimehours, regularhours, hourlyrate, regularpay, minnp, maxnp, taxamount, netpay, grosspay, overtimepay, yearlysalary;
double findnetpay(), maxnet(double, int), minnet(double, int);
double findgrosspayhourly();
double findgrosspaysalaried();
void settingthevariables(char[], int, char, char, double, double, double);
double getNetPay();
void printheaders();
void printdata();
void findtaxamount();
void printminmax(double, double);

payroll(); 
payroll(char* alastname, int aemployeeid, char ams, char apaystatus,double ahoursworked, double ahourlyrate, double ayearlysalary);
~payroll(); 
};

payroll::payroll(char* alastname, int aemployeeid, char ams, char apaystatus,double ahoursworked, double ahourlyrate, double ayearlysalary)
{
  lastname = alastname; 
  aemployeeid =  employeeid;
  ms = ams;  
  paystatus = apaystatus;
 hoursworked = ahoursworked; 
 hourlyrate = ahourlyrate; 
 yearlysalary = ayearlysalary;

}
class Employee {  
public:  
         virtual double getNetPay() const;  
         void setID(double);  
         void setFirstName(string);  
         void setLastName(string);  
         void setMaritalStatus(char);      
         void setHoursWorked(double);  
         void setHourlyRate(double);  
         void employeeSwap(Employee x[], int i, int j);
         void printdata() const; 
          
Employee();  
Employee(double id,string firstName,string lastName,char maritalStatus,double hoursWorked,double hourlyRate); 
~Employee();   
private:  
          double id;  
          string firstName, lastName;  
          char maritalStatus;  
          double hoursWorked, hourlyRate;  
}; //class employee


class SalariedEmployee : public Employee{  
public:  
         double getNetPay();  
         double setWage(double);  
         
SalariedEmployee();  
~SalariedEmployee();  
private:  
double wage;  }; // class salaried employee 

class EmployeeList {  
public:  
         void sortByNetPayAscending();  
         void printdata() const;  
         void add(Employee *);  

EmployeeList(int capacity);  
~EmployeeList();  

private:  
          const int capacity;  
          int size;  
Employee **list;  
         void employeeSwap(int, int);  
}; // class employee list


void Employee::employeeSwap(Employee x[], int i, int j){
    Employee temp;
         temp=x[i];
         x[i]=x[j];
         x[j]=temp; }// sorts the employees by netpay

void sortByNetPayAscending(Employee employees[], int numEmployees){
     
     for(int i=1; i<numEmployees; i++){
             for(int j=0; j<numEmployees-i;j++){
                     if(employees[j].getNetPay() > employees[j+1].getNetPay()){
                                 employees[j].employeeSwap(employees,j,j+1); }}}// bubble sort netpay, keeping the data indexed
}   
void payroll::findtaxamount() {
     taxrate = .30;
     taxamount = grosspay * taxrate;
}// findtaxamount

double payroll::findgrosspayhourly() {
        if (hoursworked > 40 ) {
           overtimehours = hoursworked - 40;
           regularpay = 40 * hourlyrate;
           overtimepay = 1.5* hourlyrate * overtimehours;
           grosspay = overtimepay + regularpay  ; }
        else {
            grosspay = hoursworked * hourlyrate;
            regularpay = grosspay; }
            return grosspay; }

double payroll::findgrosspaysalaried() {
        regularpay = yearlysalary/52; 
        overtimehours = hoursworked - 40; 
        grosspay = regularpay;
        if (hoursworked > 0) {
        overtimehours = hoursworked - 40;
           overtimepay = 1.5* overtimehours * (regularpay/40);
           grosspay = regularpay + overtimepay;
return grosspay;
        }// If
};//findgrosspay

double payroll::findnetpay()  {
     netpay = grosspay - taxamount;
return netpay;
}

double payroll::minnet(double minnp, int i) {
     if (i == 0) {minnp = 10000000;}
     if (netpay < minnp) {minnp = netpay;}
return minnp;
} 

double payroll::maxnet(double maxnp, int i) {
     if (i == 0) {maxnp = 0;}
     if (netpay > maxnp) {maxnp = netpay;}
return maxnp;
} 

void sortdata( payroll *employees[], int numOfEmployees)
{
for(int i=1; i<numOfEmployees; i++)
{ 
    for(int j=0; j<numOfEmployees-i;j++){
        if(employees[j]->getNetPay() > employees[j+1]->getNetPay())
        { 
            

             payroll * tmp = employees[j];
             employees[j] = employees[j+1];
             employees[j+1] = tmp;
        }//if you like you can use swap funtion
}// bubble sort netpay, keeping the data indexed 
}//sortdata
}
void payroll::printheaders(){
      
 
    cout << "------------------------------------------------------------------------------" << endl; 
    cout << "LAST NAME      OT PAY         TAX            NETPAY"   << endl; 
    cout << "-------------------------------------------------------------------------------" << endl;

}

void payroll::printdata()    {

 	 cout<<setw(15)<<left<<lastname;
   cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
 	 cout<<setw(15)<<overtimepay<<setw(15)<<taxamount<<setw(15)<<netpay<<endl; }
      


void payroll::printminmax(double minnp, double maxnp) {
     cout<<endl<<"The Max. NETPAY is $"<<maxnp<<endl;
     cout<<"The Min. NETPAY is $"<<minnp<<endl;
}

int main() {
   const int MAXSIZE = 100;  
   
    string  lastname[MAXSIZE]; 
    double overtimepay[MAXSIZE],taxamount[MAXSIZE], netpay[MAXSIZE]; 
   SalariedEmployee e;
    Employee employees[6];
    int numEmployees;
 
    payroll report;
    payroll settingthevariables;
    payroll findgrosspay;
    payroll findtaxamount ;          
    payroll findnetpay ;          
    payroll minnet;          
    payroll maxnet; 
    char alastname[14], ams, apaystatus;
    int aemployeeid,n, i=0;
    string firstName, lastName; 
    char maritalStatus,salaried;
    double employeeId, hoursWorked,wage,  ahoursworked, ayearlysalary, ahourlyrate, minnp, maxnp, ataxamount,  anetpay, 
    aovertimepay;
   
    report.printheaders();
    

payroll *employee[6];
ifstream fin;
fin.open("2252011.in");
while (fin>>alastname>>aemployeeid>>ams>>apaystatus>>ahoursworked>>ahourlyrate>>ayearlysalary) {
              payroll *ep = new payroll(alastname, aemployeeid, ams, apaystatus, ahoursworked, ahourlyrate, ayearlysalary);
              employee[i] = ep;
             i++;
}
} //out of while loop


sortdata(employee,6);

int rec_count = 0;
printheader();
while(rec_count <6)
{
              employee[rec_count]->printdata(); 
            rec_count ++;
} 
printfooter();


//delete of the allocated objects
rec_count = 0;
while(rec_count < 6)
              delete employee[i];
  
}
//end of main   
     system ("pause");
} 
Line 219 says "out of while loop" but it's actually closing main(). Your indentation is all weird and wrong, which makes it hard to see it.
Thanks. I deleted line 219. I now recieve the same erro at 241. But now the bracketts look correct. Any more ideas?
Same problem. The call to system() (which shouldn't be there at all: http://www.cplusplus.com/forum/articles/11153/ ) is outside of main(). I think your priority for that code should be to fix the indentation (and break those huge lines into 80 character lines).
Last edited on
I was using the system("pause") as the output would flash and sut off immediately. When I take out that line and the last brackett, I get a series of Linker errors- undefined reference to "Employee:: Employe()
That error might be because of line 191, at line 51 you tell the compiler that you're going to define the constructor for your Employee class but I don't see it posted here. Then down at line 191 you try to create an Employee object but there is nothing telling your program how to do that.

As a side note IDK if anyone has mentioned this yet but header files would make this much easier to trouble shoot. Your errors will tell you what file to look in and everything won't be all cluttered up.
Topic archived. No new replies allowed.