Trouble with my functions...

I am writing a payroll program which sorts netpays and can not get this compile. Can you guys give me pointers? Especially on the employee class definitions.. I am still a little confused on what the correct syntax is. Thanks




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
#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


double Employee::getNetPay() const { return hoursWorked * hourlyRate; }
void Employee::setHoursWorked(double n) { hoursWorked = n; }
         ,
void Employee::setID(double){ employeeid = n; }
void Employee::setFirstName(string);  { FirstName = n; }
void Employee::setLastName(string);  { LastName = n; }
void Employee::setMaritalStatus(char);   { MaritalStatus = n; }   
void Employee::setHourlyRate(double) { HourlyRate = n; }

void employeeSwap(Employee x[], int i, int j);{ employeeid = n; }
void printdata() const; { employeeid = n; }


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++;
}// while loop

              sortdata(employee,6);
              int rec_count = 0;
              payroll printheaders();

while(rec_count <6)
{
              employee[rec_count]->printdata(); 
              rec_count ++;
} // while count
payroll printfooter();


//delete of the allocated objects
             rec_count = 0;
             while(rec_count < 6)
             delete employee[i];
}//main 
Wow, I can't really remember how many these threads you've posted. Sorry if this has already been asked/stated somewhere else but can you answer these?

1. Is this an assignment? If so, can you please post the question too? If it's not then can you give a simple explanation of what you're trying to accomplish and the specs of your app?

2. How did you design your payroll and employee classes? Have you done any unit testing?

3. Would you mind starting from scratch? i.e design a simple class/struct to read your file and/or design a simple fuction that accepts datas and sort them?

forgive me if this post is a bit blunt, but IMHO you're banging you head against a wall here because all your problems seemed to be coming from bad design and planning on your part
This is an assignment; the program is supposed to calc. netpays for salaried/hourly employees and sort them. The program I wrote calculates fine, but I can not implement a sort function to it. I considered starting over but 1) I am under a time constraint and 2) I dont have to expertise to catch where my error is if I did start over, I have been doing this intermittently for 2 months and would probably end up where I am now.
Are you sure your sorting function is the problem? It looks ok to me...

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

void sortdata( int * parray[], int size)
{
    for(int i=1; i<size; i++)
    {
        for(int j=0; j<size-i;j++)
        {
            if(*(parray[j])>*(parray[j+1]))
            {
                int * tmp=parray[j];
                parray[j]=parray[j+1];
                parray[j+1]=tmp;
            }
        }
    }
}

void print(int * parray[], int size)
{
    for (int i=0; i<size; i++)
        cout << *(parray[i]) << ' ';
    cout << endl;
}

int main()
{
    int * parr[5]={new int(4),new int(1),new int(5),new int(2),new int(3)};

    print(parr,5);
    sortdata(parr,5);
    print(parr,5);

    cout << "hit enter to quit...";
    cin.get();
    return 0;
}

The output of the code above is:

4 1 5 2 3
1 2 3 4 5
hit enter to quit...


Last edited on
Well I was pretty sure the sorting was wrong, but youve disproved me. When I try to compile I recieve a linker reference error now, so it may be the structure of the functions
so it may be the structure of the functions

If, you're still using the above code, shouldn't your compiler throw errors at lines 64-72 at least?
Topic archived. No new replies allowed.