Payroll Program with inheritance

Pages: 12
I am writing a payroll program with inheritance that has the following requirments:

Expand the Employee Payroll program to include hourly based and salary based employees. This phase uses an array of employee objects, inheritance for different classes of employees, and polymorphism for salary computation. The 52 week yearly salary as well as number of overtime hours worked by a salary based employee is given). For salary based employees, to find the regular (gross) pay for a week, divide the salary by 52. To compute the overtime pay for a salary based employee, first find the hourly rate by dividing the gross pay by 40, and then compute overtime pay. For every employee, overtime pay, tax amount, and net pay must also be computed. In addition, the program should find the minimum and maximum net pay of all employees as well as sort the employees based on their net pay (ascending order).

This is my code:

#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
ifstream fin;
public: string employeename;
char paystat;
int n;
int hoursworked,overtimehours;
double hourlyrate,regularpay, minnp, maxnp;
double overtimepay,grosspay,taxrate,taxamount,netpay;
double totalnetpay, avgnetpay;
virtual double findgrosspay();
virtual double calculatetax();
virtual double calculatenetpay();
virtual double findavgnetpay();
void printmax(double, double);
void sortbypointers(void);
payroll();
~payroll();
void printreport(); };
payroll::payroll(){

class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked > 40){
overtimehours=hoursworked-40;
regularpay=hoursworked*hourlyrate;
overtimepay=overtimehours*(hourlyrate*1.5);
grosspay=regularpay+overtimepay;}
else
grosspay=hoursworked*hourlyrate;
regularpay=grosspay;
return grosspay;
}//findgrosspay
};
class salaried:public payroll{
public: double findgrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=hourlyrate/52;
grosspay=regularpay+overtimepay; }//IF
return grosspay;
}//findgrosspay
};
fin.open("salariedemployees.in");}
payroll::~payroll(){
fin.close();}
double payroll::calculatetax(){
taxrate=.30;
taxamount=grosspay*taxrate;
return taxamount;
}//findtaxamount
};
double payroll::calculatenetpay(){
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
return netpay;
}//calculatenetpay
};
double payroll::findavgnetpay(){
avgnetpay=totalnetpay/n;
std::cout<<endl<<"The average net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
return avgnetpay;
}//findavgnetpay
double payroll::minnet(double minnp, int n){
if(n==0) {minnp=1000000;}
if(netpay<minnp=netpay;}
std::cout<<endl<<"The minimum net pay for "<<n<<"employees is"
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//minnet
double payroll::maxnet(double maxnp, int n){
if(n==0) {maxnp=3000000;}
if(netpay<maxnp=netpay;}
std::cout<<endl<<"The maximum net pay for "<<n<<"employees is"
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
return maxnp;
}/maxnp

void sortbypointers(){
cout << "Before sorting by pointer:" << endl;
double *p[n];
int i,j;
double *temp;
int sortedflag=0;
for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
while (!sortedflag){
sortedflag=1;
for(j=0;j<n-1;j++ ){
if (*p[j]>*p[j+1]){
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
sortedflag=0; }//SWAP
}//J
}//I
cout<<endl<<"SORTED ARRAY:";
for(i=0;i<n;i++)cout<<*p[i]<<" ";
}//sortfunction




void payroll::printheadings(){
cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
cout<<" NAME HW HR REGP OT-PAY GROSS TAX NETPAY"<<endl;
cout<<"-----------------------------------------------------------"<<endl;
}//PRINTHEADINGS
void payroll::printdata(){
std::cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
std::cout<<setw(6)<<employeename<<setw(6)<<employeeid<<
setw(2)<<hoursworked<<setw(8)<<
hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
setw(8)<<taxamount<<setw(8)<<netpay<<endl;
}//PRINTDATA
void payroll::printreport(){
n=0;totalnetpay=0;
printheadings();
while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
n++; }//WHILE

findavgnetpay();
std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
}//PRINTREPORT
int main(){
payroll employee*employee[6]*report;
employee.printreport();
while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
if(apaystat=='s'){
employee[n]=new salaried();
employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
employee[n]->findgrosspay(); }//if s
if(apaystat=='h'){
employee[n]=new hourly();
employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
employee[n]->findgrosspay(); }//if h
n++;
}//WHILE

sortnetpays(netpays, n);
fin.close();

system ("pause");
}//MAIN




The only error I get is:

55 C:\Dev-Cpp\5 Phase 1 trying 2.cpp expected declaration before '}' token

I am not sure if I have just made a HUGE mess, or just a simple error?? Thanks for the help. I have a week left of a course and have 2 programs to finish while trying to work full time. Any help is greatly appreciated :).
If you could edit it and put your posts between the [c0de] this is where your code should go [/c0de] tags. Remember to replace the 0 in c0de with an o as in code.

Agghhh you have a mess of it though.

1) You cannot declare a class inside the constructor of your payroll. Declare them off by themselves.

2) }/maxnp should have // 2 slashes

3) payroll employee*employee[6]*report; I think you mean payroll employee, employee[6], report;
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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      int hoursworked,overtimehours;
      double hourlyrate,regularpay, minnp, maxnp;
      double overtimepay,grosspay,taxrate,taxamount,netpay;
      double totalnetpay, avgnetpay;
      virtual double findgrosspay();
      virtual double calculatetax();
      virtual double calculatenetpay();
      virtual double findavgnetpay();
      void printmax(double, double);
      void sortbypointers(void);
      payroll();
      ~payroll();
      void printreport(); };
      payroll::payroll(){
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
        }//findgrosspay
       };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; }//IF
       return grosspay;
       }//findgrosspay
       };
       fin.open("salariedemployees.in");}
       payroll::~payroll(){
       fin.close();}                                       
  double payroll::calculatetax(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         };
  double payroll::calculatenetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//calculatenetpay  
       };
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         std::cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {minnp=1000000;}
         if(netpay<minnp=netpay;}
         std::cout<<endl<<"The minimum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
         return minnp;
         }//minnet
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp=netpay;}
         std::cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double *p[n];
     int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<n;i++)cout<<*p[i]<<" ";
                                      }//sortfunction                           
       
  
  
  
  void payroll::printheadings(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            std::cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
            std::cout<<setw(6)<<employeename<<setw(6)<<employeeid<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0;totalnetpay=0;
          printheadings();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          calculategrosspay();
          calculatetax();
          calculatenetpay();
          printdata();
          n++; }//WHILE
          
          findavgnetpay();
          std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
          }//PRINTREPORT
          int main(){
               payroll employee,employee[6],report;
               employee.printreport();
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                     sortnetpays(netpays, n);                                                                                           
               fin.close();          
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             







Thank you! Could you please explain #1 to me a little more?
Aloha, Im guessing here that you are taking a class with ESC(SUNY) as well. I know this is unrelated to this discusion. Would you mind if I take a look at your week 6 C to see where I am making a mistake, I got it to compile but not getting any of my data.
If you post your code, I will look at it and give you any suggestions that I can that may help.
I wil post it in a new discussion
Zaita or anyone who can help.......do you have any ideas what I am doing incorrectly? I have 2 programs to finish by 12:00 midnight Friday...yikes!! Thank you kindly!

This is what it looks like now:

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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      int hoursworked,overtimehours;
      double hourlyrate,regularpay, minnp, maxnp;
      double overtimepay,grosspay,taxrate,taxamount,netpay;
      double totalnetpay, avgnetpay;
      virtual double findgrosspay();
      virtual double calculatetax();
      virtual double calculatenetpay();
      virtual double findavgnetpay();
      void printmax(double, double);
      void sortbypointers(void);
      payroll();
      ~payroll();
      void printreport(); };
      payroll::payroll(){
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
        }//findgrosspay
        };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; }//IF
       return grosspay;
       }//findgrosspay
       };
       fin.open("salariedemployees.in");}
       payroll::~payroll(){
       fin.close();}                                       
  double payroll::calculatetax(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         };
  double payroll::calculatenetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//calculatenetpay  
       };
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         std::cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {minnp=1000000;}
         if(netpay<minnp=netpay;}
         std::cout<<endl<<"The minimum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
         return minnp;
         }//minnet
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp=netpay;}
         std::cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double *p[n];
     int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<n;i++)cout<<*p[i]<<" ";
                                      }//sortfunction                           
       
  
  
  
  void payroll::printheadings(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            std::cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
            std::cout<<setw(6)<<employeename<<setw(6)<<stat<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0;totalnetpay=0;
          printheadings();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          calculategrosspay();
          calculatetax();
          calculatenetpay();
          printdata();
          n++; }//WHILE
          
          findavgnetpay();
          std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
          }//PRINTREPORT
          int main(){
               payroll employee,employee[6],report;
               employee.printreport();
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                     sortnetpays(netpays, n);                                                                                           
               fin.close();          
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             
Last edited on
You didn't read my last answer.
1) You cannot declare a class inside the constructor of your payroll. Declare them off by themselves.


1
2
3
      payroll::payroll(){ // Start Payroll Constructor
      
  class hourly: public payroll{ // Declare new Class? Cannot Do this. 


should be:
1
2
3
4
5
6
7
8
9
10
11
class Class1 {
  Class1() { /* Constructor */ }
};

class Class2 {

};

class Class3 {

};


Please, try reading the answers people give you thoroughly.
Last edited on
I have e-mailed with my professor back and forth. He has given me some help, as well as a classmate. I have edited the code, but, still have a couple of errors. Any thoughts are appreciated. Zaita, the professor wrote the code class hourly: public payroll{.......... I am thoroughly confused.

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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      float taxrate;
      double hoursworked, overtimehours, regularhours;
      double hourlyrate,regularpay,minnp,maxnp;
      double avgnetpay,taxamount,netpay,grosspay,overtimepay;
      virtual double findgrosspay();
      void setvariables(char[],int,char,char,char,double,double);
      void findtaxamount();
      void printheaders();
      void printdata();
      double minnet(double, int);
      double maxnet(double, int);
      void printminmax(double, double);
      void sortbypointers(void);
      payroll();
      ~payroll();
      };
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
        }//findgrosspay
        };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; }//IF
       return grosspay;
       }//findgrosspay
       };
   calculate.ifstream("salariedemployees.in");}
       payroll::~payroll(){
       fin.close();}                                       
  double payroll::findtaxamount(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         
  double payroll::calculatenetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//calculatenetpay  
       };
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         std::cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {minnp=1000000;}
         if(netpay<minnp=netpay;}
         std::cout<<endl<<"The minimum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
         return minnp;
         }//minnet
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp=netpay;}
         std::cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double *p[n];
     int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<n;i++)cout<<*p[i]<<" ";
                                      }//sortfunction                           
       
  
  
  
  void payroll::printheadings(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            std::cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
            std::cout<<setw(6)<<employeename<<setw(6)<<stat<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0;totalnetpay=0;
          printheadings();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          calculategrosspay();
          calculatetax();
          calculatenetpay();
          printdata();
          n++; }//WHILE
          
          findavgnetpay();
          std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
          }//PRINTREPORT
          int main(){
               payroll employee,employee[6],report;
               employee.printreport();
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                     sortnetpays(netpays, n);                                                                                           
               fin.close();          
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             


I appreciate the help!

This is the error code:

49 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected constructor, destructor, or type conversion before '.' token

49 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected `,' or `;' before '.' token

49 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected declaration before '}' token
If your tutor wrote any large amounts of this code. I'd be asking for my money back on the course fees.

I have fixed your indentation, and put comments in where the problems are. You should be able to work from here. Try to keep the indentation tidy, it makes it alot easier to read/maintain/fix the 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
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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll {
  ifstream fin;
public:
  string employeename;
  char paystat;
  int n;
  float taxrate;
  double hoursworked, overtimehours, regularhours;
  double hourlyrate, regularpay, minnp, maxnp;
  double avgnetpay, taxamount, netpay, grosspay, overtimepay;
  virtual double findgrosspay();
  void setvariables(char[], int, char, char, char, double, double);
  void findtaxamount();
  void printheaders();
  void printdata();
  double minnet(double, int);
  double maxnet(double, int);
  void printminmax(double, double);
  void sortbypointers(void);
  payroll();
  ~payroll();
};

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

class salaried: public payroll {
public:
  double findgrosspay() {
    if (hoursworked > 0) {
      overtimepay = hoursworked * (regularpay / 52 / 40);
      regularpay = hourlyrate / 52;
      grosspay = regularpay + overtimepay;
    }//IF
    return grosspay;
  }//findgrosspay
};

// Ok? WTF is this doing off by itself???
// This should be within a function somewhere.
calculate.ifstream("salariedemployees.in");}

// Format stuff nicely, it's easier to read and fix.
payroll::~payroll() {
  fin.close();
}

double payroll::findtaxamount() {
  taxrate = .30;
  taxamount = grosspay * taxrate;
  return taxamount;
}//findtaxamount

double payroll::calculatenetpay() {
  netpay = grosspay - taxamount;
  totalnetpay = totalnetpay + netpay;
  return netpay;
}//calculatenetpay  

}; // WTF is this for?

double payroll::findavgnetpay() {
  avgnetpay = totalnetpay / n;
  std::cout << endl << "The average net pay for " << n << " employees is "
      << setw(8) << setprecision(2) << fixed << left << showpoint << avgnetpay
      << endl;
  return avgnetpay;
}//findavgnetpay   


double payroll::minnet(double minnp, int n) {
  if (n == 0) {
    minnp = 1000000;
  }
  if(netpay<minnp=netpay;}
  std::cout<<endl<<"The minimum net pay for "<<n<<"employees is"  <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
  return minnp;
}//minnet


double payroll::maxnet(double maxnp, int n) {
  if(n==0) {maxnp=3000000;}
  if(netpay<maxnp=netpay;}
  std::cout<<endl<<"The maximum net pay for "<<n<<"employees is" <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
  return maxnp;
}//maxnp

void sortbypointers() {
  cout << "Before sorting by pointer:" << endl;
  double *p[n];
  int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) 
    p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)
    cout<< "$" << *p[i]<<" ";
  
  while (!sortedflag) {
    sortedflag=1;
    for(j=0;j<n-1;j++ ) {
      if (*p[j]>*p[j+1]) {
        temp=p[j];
        p[j]=p[j+1];
        p[j+1]=temp;
        sortedflag=0;}//SWAP
      }//J
    }//I   
    cout<<endl<<"SORTED ARRAY:";
    for(i=0;i<n;i++)
      cout<<*p[i]<<" ";
    }//sortfunction                           

// Where is the end of this function???

void payroll::printheadings() {
  cout << setw(40) << "-PAYROLL REPORT-" << endl;
  cout << "-----------------------------------------------------------" << endl;
  cout << " NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"
      << endl;
  cout << "-----------------------------------------------------------" << endl;
}//PRINTHEADINGS

void payroll::printdata() {
  std::cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint);
  std::cout << setw(6) << employeename << setw(6) << stat << setw(2)
      << hoursworked << setw(8) << hourlyrate << setw(8) << regularpay << setw(
      8) << overtimepay << setw(8) << grosspay << setw(8) << taxamount << setw(
      8) << netpay << endl;
}//PRINTDATA

void payroll::printreport() {
  n = 0;
  totalnetpay = 0;
  printheadings();
  while (fin >> employeename >> paystat >> hoursworked >> hourlyrate) {
    calculategrosspay();
    calculatetax();
    calculatenetpay();
    printdata();
    n++;
  }//WHILE

  findavgnetpay();
  std::cout << "The average net pay for " << n << " employees is $"
      << avgnetpay << std::endl;
}//PRINTREPORT


int main() {
  payroll employee, employee[6], report;
  employee.printreport();
  while (fin >> aemployeename >> apaystat >> ahoursworked >> ahourlyrate) {
    if (apaystat == 's') {
      employee[n] = new salaried();
      employee[n]->setvariables(aemployeename, apaystat, ahoursworked,
          ahourlyrate);
      employee[n]->findgrosspay();
    }//if s
    if (apaystat == 'h') {
      employee[n] = new hourly();
      employee[n]->setvariables(aemployeename, apaystat, ahoursworked,
          ahourlyrate);
      employee[n]->findgrosspay();
    }//if h   
    n++;
  }//WHILE

  sortnetpays(netpays, n);
  fin.close();

  system("pause");
}//MAIN 
Thank you! I changed some of the code, but, now have other errors. I am sorry if I sound ignorant, but, this is difficult for me, and I am REALLY trying. Thank you again.

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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      float taxrate;
      double hoursworked, overtimehours, regularhours;
      double hourlyrate,regularpay,totalnetpay,minnp,maxnp;
      double avgnetpay,taxamount,netpay,grosspay,overtimepay;
      virtual double findgrosspay();
      void setvariables(char[],int,char,char,char,double,double);
      virtual double findtaxamount();
      virtual double findnetpay();
      virtual double findavgnetpay();
      void printheaders();
      void printdata();
      double minnet(double, int);
      double maxnet(double, int);
      void printminmax(double, double);
      void sortbypointers(void);
      payroll();
      ~payroll();
      };
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
        }//findgrosspay
        };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; }//IF
       return grosspay;
       }//findgrosspay
       };
  
       payroll::payroll(){
       fin.open("salariedemployees.in"); }
       payroll::~payroll() {
       fin.close();}                                       
  double payroll::findtaxamount(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         
  double payroll::findnetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//findnetpay  
       
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         std::cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {
                  minnp=1000000;
                  }
         if(netpay<minnp=netpay);}
         std::cout<<std::endl<<"The minimum net pay for "<<n<<" employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<std::endl;
         return minnp;
         }//minnet
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp=netpay;}
         std::cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double *p[n];
     int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<n;i++)cout<<*p[i]<<" ";
                                      }//sortfunction                           
       
  
  
  
  void payroll::printheadings(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            std::cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
            std::cout<<setw(6)<<employeename<<setw(6)<<stat<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0;totalnetpay=0;
          printheadings();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          calculategrosspay();
          calculatetax();
          calculatenetpay();
          printdata();
          n++; }//WHILE
          
          findavgnetpay();
          std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
          }//PRINTREPORT
          int main(){
               payroll employee,employee[6],report;
               employee.printreport();
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                     sortnetpays(netpays, n);                                                                                           
               fin.close();          
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             
These are the errors:

78 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp non-lvalue in assignment

78 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp At global scope:

79 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected constructor, destructor, or type conversion before '<<' token

79 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected `,' or `;' before '<<' token

81 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected unqualified-id before "return"

81 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected `,' or `;' before "return"

82 C:\Dev-Cpp\5 Phase 1 trying 2 5 3.cpp expected declaration before '}' token
Any thoughts are greatly appreciated.
see comment below:
(the same comment goes for the double payroll::maxnet(double maxnp, int n) function )

1
2
3
4
5
6
7
8
9
  double payroll::minnet(double minnp, int n){
         if(n==0) {
                  minnp=1000000;
                  }
         if(netpay<minnp=netpay);}  // something wrong here 
         std::cout<<std::endl<<"The minimum net pay for "<<n<<" employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<std::endl;
         return minnp;
         }//minnet 
Thank you, I fixed those two functions, here is the code now:

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
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      float taxrate;
      double hoursworked, overtimehours, regularhours;
      double hourlyrate,regularpay,totalnetpay,minnp,maxnp;
      double avgnetpay,taxamount,netpay,grosspay,overtimepay;
      virtual double findgrosspay();
      void setvariables(char[],int,char,char,char,double,double);
      virtual double findtaxamount();
      virtual double findnetpay();
      virtual double findavgnetpay();
      void printheaders();
      void printdata();
      double minnet(double, int);
      double maxnet(double, int);
      void printminmax(double, double);
      void printreport();
      void sortbypointers(void);
      payroll();
      ~payroll();
      };
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
        }//findgrosspay
        };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; }//IF
       return grosspay;
       }//findgrosspay
       };
  
       payroll::payroll(){
       fin.open("salariedemployees.in"); }
       payroll::~payroll() {
       fin.close();}                                       
  double payroll::findtaxamount(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         
  double payroll::findnetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//findnetpay  
       
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {
                  minnp=1000000;
                  }
         if(netpay<minnp) {minnp=netpay;}
         cout<<endl<<"The minimum net pay for "<<n<<" employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
         return minnp;
         }//minnet
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp) {maxnp=netpay;}
         cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double*p[n];
     int i,j;
  double *temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << *p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (*p[j]>*p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<n;i++)cout<<*p[i]<<" ";
                                      }//sortfunction                           
                                      

  
  
  void payroll::printheaders(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
            cout<<setw(6)<<employeename<<setw(6)<<stat<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0;totalnetpay=0;
          printheaders();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          findgrosspay();
          findtaxamount();
          findnetpay();
          printdata();
          n++; }//WHILE
          
          findavgnetpay();
          std::cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<std::endl;
          }//PRINTREPORT
          int main(){
               payroll employee,employee[6],report;
               employee.printreport();
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                     sortnetpay(netpay, n);                                                                                           
               fin.close();          
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             


Now I seem to have errors with the pointer array :(......


C:\Dev-Cpp\Module 6 trying.cpp In function `void sortbypointers()':
94 C:\Dev-Cpp\Module 6 trying.cpp `n' undeclared (first use this function)
98 C:\Dev-Cpp\Module 6 trying.cpp `p' undeclared (first use this function)
98 C:\Dev-Cpp\Module 6 trying.cpp `netpay' undeclared (first use this function)
C:\Dev-Cpp\Module 6 trying.cpp In member function `void payroll::printdata()':
125 C:\Dev-Cpp\Module 6 trying.cpp expected primary-expression before '<<' token
C:\Dev-Cpp\Module 6 trying.cpp In function `int main()':
144 C:\Dev-Cpp\Module 6 trying.cpp conflicting declaration 'payroll employee[6]'
144 C:\Dev-Cpp\Module 6 trying.cpp 'employee' has a previous declaration as `payroll employee'
144 C:\Dev-Cpp\Module 6 trying.cpp declaration of `payroll employee[6]'
144 C:\Dev-Cpp\Module 6 trying.cpp conflicts with previous declaration `payroll employee'
146 C:\Dev-Cpp\Module 6 trying.cpp `fin' undeclared (first use this function)
146 C:\Dev-Cpp\Module 6 trying.cpp `aemployeename' undeclared (first use this function)
146 C:\Dev-Cpp\Module 6 trying.cpp `apaystat' undeclared (first use this function)
146 C:\Dev-Cpp\Module 6 trying.cpp `ahoursworked' undeclared (first use this function)
146 C:\Dev-Cpp\Module 6 trying.cpp `ahourlyrate' undeclared (first use this function)
148 C:\Dev-Cpp\Module 6 trying.cpp `n' undeclared (first use this function)
158 C:\Dev-Cpp\Module 6 trying.cpp `netpay' undeclared (first use this function)
158 C:\Dev-Cpp\Module 6 trying.cpp `sortnetpay' undeclared (first use this function)



There seems to be a problem with my variables.
This should get rid of a couple of the errors (starting at line 92):
void sortbypointers() should be part of the payroll class
so should be defined as
void payroll::sortbypointers()
Once you have done that you will get an error about line 94 again because
you cannot declare an array with a variable subscript:
double*p[n]; //wrong - cannot set the size of an array using a variable like this.

Your main function is somewhat screwed up.
Thank you. I changed that. There is something wrong with my variables. Do you have any ideas? Thanks kindly.

I changed my code in alot of ways, but, now I seem to have troubles with declaring n............

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
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class payroll{
      ifstream fin;
      public: string employeename;
      char paystat;
      int n;
      float taxrate;
      double hoursworked, overtimehours, regularhours;
      double hourlyrate,regularpay,totalnetpay,minnp,maxnp;
      double avgnetpay,taxamount,netpay,grosspay,overtimepay;
      virtual double findgrosspay();
      void setvariables(char[],int,char,char,char,double,double);
      virtual double findtaxamount();
      virtual double findnetpay();
      virtual double findavgnetpay();
      void printheaders();
      void printdata();
      double minnet(double, int);
      double maxnet(double, int);
      void printminmax(double, double);
      void printreport();
      void sortbypointers();
      payroll();
      ~payroll();
      };
      
  class hourly: public payroll{
       public: double findgrosspay(){
       if(hoursworked > 40){
       overtimehours=hoursworked-40;
       regularpay=hoursworked*hourlyrate;
       overtimepay=overtimehours*(hourlyrate*1.5);
       grosspay=regularpay+overtimepay;}
       else{
       grosspay=hoursworked*hourlyrate;
       regularpay=grosspay;
       return grosspay;
       }//IF
        };//findgrosspay
        };
  class salaried:public payroll{
        public: double findgrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       grosspay=regularpay+overtimepay; 
       return grosspay;
       }//If 
       };//findgrosspay
       };
  
       payroll::payroll(){
       fin.open("salariedemployees.in"); }
       payroll::~payroll() {
       fin.close();}                                       
  double payroll::findtaxamount(){
         taxrate=.30;
         taxamount=grosspay*taxrate;
         return taxamount;
         }//findtaxamount
         
  double payroll::findnetpay(){
       netpay=grosspay-taxamount;
       totalnetpay=totalnetpay+netpay;
       return netpay;
       }//findnetpay  
       
  double payroll::findavgnetpay(){
         avgnetpay=totalnetpay/n;
         cout<<endl<<"The average net pay for "<<n<<" employees is "
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
         return avgnetpay;
         }//findavgnetpay    
  double payroll::minnet(double minnp, int n){
         if(n==0) {
                  minnp=1000000;
                  }
         if(netpay<minnp) {minnp=netpay;}
         cout<<endl<<"The minimum net pay for "<<n<<" employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
         return minnp;
         }//minnet
         
  double payroll::maxnet(double maxnp, int n){
         if(n==0) {maxnp=3000000;}
         if(netpay<maxnp) {maxnp=netpay;}
         cout<<endl<<"The maximum net pay for "<<n<<"employees is"
         <<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
         return maxnp;
         }//maxnp
         
  void payroll:: sortbypointers(){ 
     cout << "Before sorting by pointer:" << endl;    
     double p[100];
     int i,j;
  double temp;
  int sortedflag=0;
  for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
  for(i=0;i<n;i++)cout<< "$" << p[i]<<" ";
  while (!sortedflag){
   sortedflag=1;
   for(j=0;j<n-1;j++ ){  
      if (p[j]>p[j+1]){ 
        temp=p[j];
     p[j]=p[j+1];
     p[j+1]=temp;
     sortedflag=0;    }//SWAP
     }//J
     }//I   
       cout<<endl<<"SORTED ARRAY:";
       for(i=0;i<100;i++)cout<<p[i]<<" ";
                                      }//sortfunction                           
                                      

  
  
  void payroll::printheaders(){
       cout<<setw(40)<<"-PAYROLL REPORT-"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       cout<<" NAME   STAT     HW     HR  REGP     OT-PAY  GROSS   TAX   NETPAY"<<endl;
       cout<<"-----------------------------------------------------------"<<endl;
       }//PRINTHEADINGS
       void payroll::printdata(){
            cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
          cout<<setw(6)<<employeename<<setw(6)<<paystat<<
            setw(2)<<hoursworked<<setw(8)<<
            hourlyrate<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<
            setw(8)<<taxamount<<setw(8)<<netpay<<endl; 
            }//PRINTDATA
     void payroll::printreport(){
          n=0,totalnetpay=0;
          printheaders();
          while(fin>>employeename>>paystat>>hoursworked>>hourlyrate){
          findgrosspay();
          findtaxamount();
          findnetpay();
          printdata();
          sortbypointers();
          n++; }//WHILE
          
          findavgnetpay();
          cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<endl;
          }//PRINTREPORT
          int main(){
           int  n=0;
               payroll employee[6],report;
               employee[0].printreport();
               
               string aemployeename;
               char apaystat;
               double ahoursworked, ahourlyrate;
               ifstream fin("salariedemployees.in");
               while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){
                 if(apaystat=='s'){
                    employee[n]=new salaried();
                    employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                    employee[n]->findgrosspay(); }//if s
                    
                  if(apaystat=='h'){
                     employee[n]=new hourly();
                     employee[n]->setvariables(aemployeename,apaystat,ahoursworked,ahourlyrate);
                     employee[n]->findgrosspay(); }//if h   
                     n++;
                     }//WHILE
                     
                       sortnetpays(netpay,n);
                       fin.close();                                                                                  
                
               
               system ("pause");
               }//MAIN
                                                                                                              
                                             


Can anyone please help? I have this program as well as one other due by tomorrow and I am starting to panic. I have been working on this diligently, but, need some serious help. Thank you kindly.
Pages: 12