Payroll Net Pay with Pointers

Alright, after what seems like forever I'm on the last stage of modifying my Payroll Program. This time I have to sort using pointers and I only have to sort the Net Pay category.

Using one of my earlier programs I've removed content from it until it's in a state where it runs but contains no sorting functions.
____________________________________________________________________________
So now I've to a working program that lacks any kind of sorting and looks like this.

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
#include <iostream>
#include <fstream>//file input output stream
#include <iomanip>
#include <string>
using namespace std;
 //function prototypes
int readalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[], int n);
 void findovertimehours(int[], int[], int);
 void findovertimepay(int[], float[], float[], int);
 void findregularhours(int[], int[], int);
 void findregularpay(int[], float[], float[], int);
 void findgrosspay(float[], float[], float[], int);
 void findtaxrate(float[], float[], int);
 void findtaxamount(float[], float[], float[], int);
 void findnetpay(float[], float[], float[], int);
 void printalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[],
	 float overtimepay[], float grosspay[], float taxamount[],
	 float netpay[], int n);

 int main(){
	 const int MAXSIZE = 100; //for maximum of 100 employees
	
		 //decleration of variables
		int n;
	 long int id[MAXSIZE];
	 int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
	 int regularhours[MAXSIZE];
	 float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
		 overtimepay[MAXSIZE], grosspay[MAXSIZE];
	 float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];
	 string fname[MAXSIZE], lname[MAXSIZE];
		 //function calls
	 n = readalldata(id, fname, lname, hoursworked, hourlyrate, MAXSIZE); //get all data
		 findovertimehours(hoursworked, overtimehours, n);
	 findovertimepay(overtimehours, hourlyrate, overtimepay, n);
	 findregularhours(hoursworked, regularhours, n);
	 findregularpay(regularhours, regularpay, hourlyrate, n);
	 findgrosspay(regularpay, overtimepay, grosspay, n);
	 findtaxrate(grosspay, taxrate, n);
	 findtaxamount(grosspay, taxamount, taxrate, n);
	 findnetpay(grosspay, netpay, taxamount, n);
	 printalldata(id, fname, lname, hoursworked, hourlyrate, overtimepay,
		 grosspay, taxamount, netpay, n);
	
	 printalldata(id, fname, lname, hoursworked, hourlyrate, overtimepay,
		 grosspay, taxamount, netpay, n);
	 return 0;
	
		
}//MAIN
 //function definitions
 int readalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[], int n){
	 ifstream fin("employee.txt");
	 n = 0;
	
	 while (fin >> id[n] >> fname[n] >> lname[n] >> hoursworked[n] >> hourlyrate[n])
		 n++;
	 fin.close();
	 return n;
	
}//READALLDATA

 void findovertimehours(int hoursworked[], int overtimehours[], int n){
	 for (int i = 0; i<n; i++){
		 if (hoursworked[i]>40) overtimehours[i] = hoursworked[i] - 40;
		 else overtimehours[i] = 0;
		
	}//FOR
	
		
}//FINDOVERTIMEHOURS

 void findovertimepay(int overtimehours[], float hourlyrate[],
 float overtimepay[], int n){
	 for (int i = 0; i<n; i++){
		 overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
		
	}//FOR
	
		
}//FINDOVERTIMEPAY

 void findregularhours(int hoursworked[], int regularhours[], int n){
	 for (int i = 0; i<n; i++){
		 if (hoursworked[i]>40) regularhours[i] = 40;
		 else regularhours[i] = hoursworked[i];
		
	}//FOR
	
}//FINDREGULARHOURS
 void findregularpay(int regularhours[], float regularpay[],
 float hourlyrate[], int n){
	 for (int i = 0; i<n; i++){
		 regularpay[i] = regularhours[i] * hourlyrate[i];
		
	}//FOR
	
}//FINDREGULARPAY
 void findgrosspay(float regularpay[], float overtimepay[],
	 float grosspay[], int n){
	 for (int i = 0; i<n; i++){
		 grosspay[i] = regularpay[i] + overtimepay[i];
		
	}//FOR
	
}//FINDGROSSPAY

 void findtaxrate(float grosspay[], float taxrate[], int n){
	 for (int i = 0; i<n; i++){
		 if (grosspay[i]>4000.00) taxrate[i] = 0.40;
		 else if (grosspay[i]>3000.00) taxrate[i] = 0.30;
		 else if (grosspay[i]>1000.00) taxrate[i] = 0.20;
		 else taxrate[i] = 0.10;
				
	}//FOR
	
}//FINDTAXRATE
 void findtaxamount(float grosspay[], float taxamount[],
 float taxrate[], int n){
	 for (int i = 0; i<n; i++){
		 taxamount[i] = grosspay[i] * taxrate[i];
		
			
	}//FOR
	
		
}//FINDTAXAMOUNT

 void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
	 for (int i = 0; i<n; i++){
		 netpay[i] = grosspay[i] - taxamount[i];
		
	}//FOR
	
}//FINDNETPAY
 void printalldata(long int id[], string fname[], string lname[], int hoursworked[], float hourlyrate[],
	 float overtimepay[], float grosspay[], float taxamount[],
	 float netpay[], int n){
	 float totalNetPay = 0;
	 int i = 0;
	 cout << setw(58) << "PAYROLL INSTITUTE" << endl;
	 cout << setw(50) << "106 EASY WAYS LANE" << endl;
	 cout << setw(53) << "PLEASANTVILLE N.Y. 11068" << endl;
	 cout << " " << endl << endl;
	 cout <<
		"==================================================================== " << endl;
	 cout << "EMP ID" << setw(12)
		 << "FIRST NAME" << setw(12)
		 << "LAST NAME" << setw(7)
		 << "HOURS" << setw(6)
		 << "RATE" << setw(11)
		 << "OVERPAY" << setw(11)
		 << "GROSSPAY" << setw(8)
		 << "TAX" << setw(11)
		 << "NETPAY" << endl;
	 cout << fixed << setprecision(2);
	 for (int i = 0; i<n; i++){
		 cout << "" << id[i] << setw(11)
			 << fname[i] << setw(13)
			 << lname[i] << setw(7)
			 << hoursworked[i] << setw(9)
			 << hourlyrate[i] << setw(8)
			 << overtimepay[i] << setw(12)
			 << grosspay[i] << setw(10)
			 << taxamount[i] << setw(10)
			 << netpay[i] << endl;
		 totalNetPay += netpay[i];
	}//FOR
	 cout <<
		"==================================================================== " << endl;
	 cout << "The net pay average of the employees are: " << totalNetPay / n << endl;
	 system("pause");
	 cout << endl;
	 cout << endl;
	
}//PRINTALLDATA 

_____________________________________________________________________________
My hints for how to add pointers to the program are...

int *np,tmp;

for (i=0,i<n; i++) np=&netpay[i]; //associating the netpay to np;

temp=np[i];//storing the pointer to a temp
_____________________________________________________________________________
I've been fooling around trying to sort the Net Pay by pointers using these hints for a bit now and I'm still not getting it. Can someone help me out with this silly Payroll program one last time please?

Edit: Please if anyone can help I'd really appreciate it. I've continued to work on this throughout the day and I'm still getting nowhere.
Last edited on
I've been working on this most the day so far and I've experimented with what I think is a simple example program that may be taking me in the right direction.

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
#include <iostream>
using namespace std;
void main(){
	const int n = 5;
	int item[n] = { 2,5,3,1,4};
	int *p[n];

int i, j;
	int *temp;
	int sortedflag = 0;
	for (i = 0; i < n; i++) p[i] = item + i;//INIALIZING 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] << "";
	cout << endl;
	system("PAUSE");
}//MAIN 


I'm still trying to work out a way to sort my net pay with pointers in my payroll program though. I could really use some help if anyone is willing.
So I'm still working on this and though I haven't gotten it to work I thought I'd present what I've done if for no other reason then to prove that I'm trying.

Here's what I've got 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
165
166
167
168
169
170
171
#include <iostream>
#include<fstream>
#include <iomanip>
using namespace std;

//function prototypes
int readalldata(long int[], int[], float[], const int);
void findovertimehours(int[], int[], int);
void findovertimepay(int[], float[], float[], int);
void findregularhours(int[], int[], int);
void findregularpay(int[], float[], float[], int);
void findgrosspay(float[], float[], float[], int);
void findtaxrate(float[], float[], int);
void findtaxamount(float[], float[], float[], int);
void findnetpay(float[], float[], float[], int);
void printalldata(long int[], int[], float[], float[], float[], float[], float[], int);
void sort(float[], int);
void pointer_array_sort(float*netpay, int n);
int main(){
	const int MAXSIZE = 100;   //for maximum of 100 employees

	//decleration of variables
	int n;
	long int id[MAXSIZE];
	int hoursworked[MAXSIZE], overtimehours[MAXSIZE];
	int regularhours[MAXSIZE];
	float hourlyrate[MAXSIZE], regularpay[MAXSIZE],
		overtimepay[MAXSIZE], grosspay[MAXSIZE];
	float taxrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE];

	//function calls
	n = readalldata(id, hoursworked, hourlyrate, MAXSIZE); //get all data
	findovertimehours(hoursworked, overtimehours, n);
	findovertimepay(overtimehours, hourlyrate, overtimepay, n);
	findregularhours(hoursworked, regularhours, n);
	findregularpay(regularhours, regularpay, hourlyrate, n);
	findgrosspay(regularpay, overtimepay, grosspay, n);
	findtaxrate(grosspay, taxrate, n);
	findtaxamount(grosspay, taxamount, taxrate, n);
	findnetpay(grosspay, netpay, taxamount, n);
	printalldata(id, hoursworked, hourlyrate, overtimepay,
	grosspay, taxamount, netpay, n);
	sort(netpay, n);
	printalldata(id, hoursworked, hourlyrate, overtimepay,
	grosspay, taxamount, netpay, n);
	return 0;
}//MAIN

//function definitions
int readalldata(long int id[], int hoursworked[], float hourlyrate[], int n){
	ifstream fin("employee.txt");
	n = 0;

	while (fin >> id[n] >> hoursworked[n] >> hourlyrate[n]) n++;
	fin.close();
	return n;
}//READALLDATA

void findovertimehours(int hoursworked[], int overtimehours[], int n){
	for (int i = 0; i<n; i++){
		if (hoursworked[i]>40) overtimehours[i] = hoursworked[i] - 40;
		else overtimehours[i] = 0;
	}//FOR
}//FINDOVERTIMEHOURS

void findovertimepay(int overtimehours[], float hourlyrate[],
	float overtimepay[], int n){
	for (int i = 0; i<n; i++){
		overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
	}//FOR
}//FINDOVERTIMEPAY

void findregularhours(int hoursworked[], int regularhours[], int n){
	for (int i = 0; i<n; i++){
		if (hoursworked[i]>40) regularhours[i] = 40;
		else regularhours[i] = hoursworked[i];
	}//FOR
}//FINDREGULARHOURS

void findregularpay(int regularhours[], float regularpay[],
	float hourlyrate[], int n){
	for (int i = 0; i<n; i++){
		regularpay[i] = regularhours[i] * hourlyrate[i];
	}//FOR
}//FINDREGULARPAY
void findgrosspay(float regularpay[], float overtimepay[],
	float grosspay[], int n){
	for (int i = 0; i<n; i++){
		grosspay[i] = regularpay[i] + overtimepay[i];
	}//FOR
}//FINDGROSSPAY

void findtaxrate(float grosspay[], float taxrate[], int n){
	for (int i = 0; i<n; i++){
		if (grosspay[i]>4000.00) taxrate[i] = 0.40;
		else if (grosspay[i]>3000.00) taxrate[i] = 0.30;
		else if (grosspay[i]>1000.00) taxrate[i] = 0.20;
		else taxrate[i] = 0.10;
	}//FOR
}//FINDTAXRATE

void findtaxamount(float grosspay[], float taxamount[],
	float taxrate[], int n){
	for (int i = 0; i<n; i++){
		taxamount[i] = grosspay[i] * taxrate[i];
	}//FOR
}//FINDTAXAMOUNT

void findnetpay(float grosspay[], float netpay[], float taxamount[], int n){
	for (int i = 0; i<n; i++){
		netpay[i] = grosspay[i] - taxamount[i];
	}//FOR
}//FINDNETPAY

void printalldata(long int id[], int hoursworked[], float hourlyrate[],
	float overtimepay[], float grosspay[], float taxamount[],
	float netpay[], int n){
	float totalNetPay = 0;

	int i = 0;
	cout << setw(50) << "PAYROLL INSTITUTE" << endl;
	cout << setw(42) << "106 EASY WAYS LANE" << endl;
	cout << setw(45) << "PLEASANTVILLE N.Y. 11068" << endl;
	cout << " " << endl << endl;
	cout << "======================================================= " << endl;
	cout << fixed << setprecision(2);
	cout << "EMP ID" << setw(8)
		<< "HOURS" << setw(7)
		<< "RATE" << setw(13)
		<< "OVERPAY" << setw(11)
		<< "GROSSPAY" << setw(8)
		<< "TAX" << setw(11)
		<< "NETPAY" << endl;
	for (i; i<n; i++){
		totalNetPay += netpay[i];
		cout << "" 
			<< id[i] << setw(8)
			<< hoursworked[i] << setw(10)
			<< hourlyrate[i] << setw(10)
			<< overtimepay[i] << setw(12)
			<< grosspay[i] << setw(10)
			<< taxamount[i] << setw(10)
			<< netpay[i] << endl;
	}//FOR

	cout << "====================================================== " << endl;
	cout << "The net pay average of the employees is: " << totalNetPay / i << endl;
	cout << endl;
	system("PAUSE");
	cout << endl;
	cout << endl;
}//PRINTALLDATA
void pointer_array_sort(float*netpay, int n);
int i, j;
int *netpay, temp;
int sortedflag = 0;
for (i = 0, i<n; i++) netpay = &netpay[i]; //associating the netpay
while (!sortedflag){
	sortedflag = 1;
	for (j = 0; j < n - 1; j++){
		if (*p[j]>*p[j + 1]){
			temp = netpay[i];//storing the pointer to a temp
			p[j] = p[j + 1];
			p[j + 1] = temp;
			sortedflag = 0;
		}//SWAP
	}//J
}//I

}
//end source code 

_____________________________________________________________________
If anyone could take a look at it for me and give me advice about what I'm doing wrong it would be great. I think I am slowly working though it but I'm still stumped at the moment.
Topic archived. No new replies allowed.