C++ Payroll program


Question
I had to add the exsel sort to my Payroll program, which the code was provided, but it's not running.

My Code:
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
const int MAX = 2;
class payroll{
ifstream fin;
char employeeid[12];
char employeename[20];
char maritalstatus;
int hoursworked,overtime;
int numberOfEmployees;
int totalEmployeeCount;
char employee;
int n;
int i, j;
double hourlyrate, overtimepay, regularpay, hourlygrosspay, salarygrosspay, taxrate, taxamount, netpay, averagenetpay;
void calculatehourlygrosspay();
void calculatesalarygrosspay();
void calculatehourlytax();
void calculatesalarytax();
void calculatehourlynetpay();
void calculatesalarynetpay();
void calculateaveragenetpay();
void sortNetPayUsingExselSort();
int printheader();
void printdata();
public: payroll();
~payroll();
void printreport(); };
payroll::payroll(){
fin.open("payroll.txt");}//CONSTRUCTOR
payroll::~payroll(){
fin.close(); }//DESTRUCTOR
void payroll::calculatehourlygrosspay(){
if(hoursworked > 40){
overtime = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtime * (hourlyrate * 1.5);
hourlygrosspay = regularpay + overtimepay; }//IF
else hourlygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatehourlytax(){
if (hourlygrosspay >= 500) taxrate = .20;
else if(hourlygrosspay > 200.00) taxrate = .20;
else taxrate = .10;
if(maritalstatus == 'S'|| maritalstatus=='s')
taxrate = taxrate + .05;
taxamount = hourlygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatehourlynetpay(){
netpay = hourlygrosspay - taxamount; }//CALCULATENETPAY
void payroll::calculatesalarygrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=hourlyrate/52;
salarygrosspay=regularpay+overtimepay; }//If
else salarygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatesalarytax(){
if (salarygrosspay >= 500) taxrate = .20;
else if(salarygrosspay > 200.00) taxrate = .20;
else taxrate = .10;
if(maritalstatus == 'S'|| maritalstatus=='s')
taxrate = taxrate + .05;
taxamount = salarygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatesalarynetpay(){
netpay = salarygrosspay - taxamount; }//CALCULATENETPAY
void payroll :: calculateaveragenetpay(){
averagenetpay=netpay / 2; }//CALCULATEAVERAGENETPAY
//Sort the employee object array in ascending
int printHeader(); //call function to print the header
char employee[0], printData(); //print the first element of employee object array
int i, j;
int totalEmployeeCount;
//initial loop to the netPay array
for ( i = 1; i < totalEmployeeCount; i++ ){
//second loop to actual values
for ( j = 0; j < totalEmployeeCount - i; j++ ){
if ( employee[j]->netPay > employee[j+1]->netPay )
payroll * temp;
//do the actual swap
temp = employee[j];
employee[j] = employee[j+1];
employee[j+1] = temp;
} //end if
}//end for loop
} //end for loop
==========
void sortNetPayUsingExselSort(employee * employees[], int numberOfEmployees)
{
int lower, upper, sortflag = 0, sml = 0, scan = 0;
lower = 0;
upper = numberOfEmployees - 1;
while( (lower < upper) && (sortflag == 1) )
{
sml = lower;
sortflag = 0;
scan = lower + 1;
while (scan <= upper - ...)
{
if( employees[scan]->getNetPay() > employees[scan + 1]->getNetPay() )
{
swap(employees, scan, scan + 1);
sortflag = ...;
if( employees[scan]->getNetPay() < employees[sml]->...)
{
sml = scan;
}
}
scan++;
} // while
swap(employees, lower, sml);
upper = upper - 1;
lower = lower + ...;
} // while
void payroll::printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<taxamount<<setw(8)
<<netpay<<setw(8)<<averagenetpay<<endl; }//PRINTDATA
void payroll::printreport(){
int i = 0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
calculatehourlygrosspay();
calculatesalarygrosspay();
calculatehourlytax();
calculatesalarytax();
calculatehourlynetpay();
calculatesalarynetpay();
calculateaveragenetpay();
sortNetPayUsingExselSort();
printdata();
i++; }//WHILE
}//PRINTREPORT
int main(){
payroll employee;
employee.printreport(); }//MAIN
Please edit your post and use code tags.
http://www.cplusplus.com/articles/jEywvCM9/
Thx
If it helps, one could even use online text formatter at

http://prettyprinter.de/

to save some work and then paste the result here inside <code> tags.
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
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
const int MAX = 2;
class payroll{
	ifstream fin;
	char employeeid[12];
	char employeename[20];
	char maritalstatus;
	int hoursworked,overtime;
	int numberOfEmployees;
	int totalEmployeeCount;
	char employee;
	int n;
	int i, j;
	double hourlyrate, overtimepay, regularpay, hourlygrosspay, salarygrosspay, taxrate, taxamount, netpay, averagenetpay;
	void calculatehourlygrosspay();
	void calculatesalarygrosspay();
	void calculatehourlytax();
	void calculatesalarytax();
	void calculatehourlynetpay();
	void calculatesalarynetpay();
	void calculateaveragenetpay();
	void sortNetPayUsingExselSort();
	int printheader();
	void printdata();
public: payroll();
	~payroll();
	void printreport(); };
payroll::payroll(){
	fin.open("payroll.txt");}//CONSTRUCTOR
	payroll::~payroll(){
	fin.close(); }//DESTRUCTOR
	void payroll::calculatehourlygrosspay(){
		if(hoursworked > 40){
			overtime = hoursworked - 40;
			regularpay = hoursworked * hourlyrate;
			overtimepay = overtime * (hourlyrate * 1.5);
			hourlygrosspay = regularpay + overtimepay; }//IF 	
else hourlygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatehourlytax(){
if (hourlygrosspay >= 500) taxrate = .20;
	else if(hourlygrosspay > 200.00) taxrate = .20;
	else taxrate = .10;
	if(maritalstatus == 'S'|| maritalstatus=='s')
			taxrate = taxrate + .05;
	taxamount = hourlygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatehourlynetpay(){
		netpay = hourlygrosspay - taxamount; }//CALCULATENETPAY
void payroll::calculatesalarygrosspay(){
       if(hoursworked>0){         
       overtimepay=hoursworked*(regularpay/52/40);
       regularpay=hourlyrate/52;
       salarygrosspay=regularpay+overtimepay; }//If  
else salarygrosspay = hoursworked * hourlyrate; }//CALCULATEGROSSPAY
void payroll ::calculatesalarytax(){
if (salarygrosspay >= 500) taxrate = .20;
	else if(salarygrosspay > 200.00) taxrate = .20;
	else taxrate = .10;
	if(maritalstatus == 'S'|| maritalstatus=='s')
			taxrate = taxrate + .05;
	taxamount = salarygrosspay * taxrate; }//CALCULATETAX
void payroll :: calculatesalarynetpay(){
		netpay = salarygrosspay - taxamount; }//CALCULATENETPAY		
void payroll :: calculateaveragenetpay(){
         averagenetpay=netpay / 2; }//CALCULATEAVERAGENETPAY
 //Sort the employee object array in ascending
int printHeader(); //call function to print the header
   char employee[0], printData(); //print the first element of employee object array
   int i, j;
   int totalEmployeeCount;
   //initial loop to  the netPay array
   for ( i = 1; i < totalEmployeeCount; i++ ){
       //second loop to actual values
       for ( j = 0; j < totalEmployeeCount - i; j++ ){
           if ( employee[j]->netPay > employee[j+1]->netPay )
              payroll * temp;
              //do the actual swap
              temp = employee[j];
              employee[j] = employee[j+1];
              employee[j+1] = temp;
           } //end if  
       }//end for loop
   } //end for loop
==========        
void sortNetPayUsingExselSort(employee * employees[], int numberOfEmployees)
{
        int lower, upper, sortflag = 0, sml = 0, scan = 0;
        lower = 0;
        upper = numberOfEmployees - 1;
    while( (lower < upper) && (sortflag == 1) )
        {
        	sml = lower;
            sortflag = 0;
            scan = lower + 1;
	while (scan <= upper - ...)
        {
       if( employees[scan]->getNetPay() > employees[scan + 1]->getNetPay() )
      {
    	swap(employees, scan, scan + 1);  
    	sortflag = ...;
        if( employees[scan]->getNetPay() < employees[sml]->...)
      {
        sml = scan;
    }
       }
	   scan++;
  } // while
 	 swap(employees, lower, sml);
     upper = upper - 1;
     lower = lower + ...;
  } // while
void payroll::printdata(){
		cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
		cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
		<<hoursworked<<setw(3)<<overtime<<setw(8)<<taxamount<<setw(8)
		<<netpay<<setw(8)<<averagenetpay<<endl; }//PRINTDATA
void payroll::printreport(){
		int i = 0;
		printheadings();
		while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
			calculatehourlygrosspay();
			calculatesalarygrosspay();
			calculatehourlytax();
			calculatesalarytax();
			calculatehourlynetpay();
			calculatesalarynetpay();
			calculateaveragenetpay();
			sortNetPayUsingExselSort();
			printdata();
			i++; }//WHILE
		}//PRINTREPORT
int main(){
		payroll employee;
		employee.printreport(); }//MAIN 

It is really messed up !

So many things wrong , a lot of missing brackets , do not write ... , the method sortNetPay is missing payroll :: , there is no employee * , since there is no employee class , it is a char in the payroll class ... your class payroll have many attributes , but none are initialized in the constructor , Line 73 you are declaring a local variable having the same name than your class attribute -> totalEmployeeCount , Line 71 put a semicolon not a comma , Line 78 is missing an opened bracket , Line 114 you are closing the while with a bracket but what about the method ? But event doing all this , it is still buggy . My advise is your create a class Employee . Note I use a capital for a class , as well for payroll -> Payroll . For attributes started names with m_

. Then you put commented lines where you did not finish (...) . Once that done , reply your code . But before that look at your compiler debug log to see what errors you are getting.

Reminder :
- Classes start with a capital
- attributes start with m_ and a letter to specify the type -> ex : m_bIsFired , is a boolean attribute , m_pEmployee is a pointer of Employee , m_cByte for a char attribute , etc.
- When writing a name (attribute,method,class,etc) use capitals for each words except for the first word of a method -> sortNetPay() method , PayRoll (class) , m_iTotalEmployeeCount (attribute)
- write your brackets that way !
void Payroll::printData(void)
{

}

not like that !
void Payroll::printData(void){

}

Do these modifications and then reply . Thanks
Topic archived. No new replies allowed.