sort pointer???

Hello,
My mom is taking a mid term on C++, she is taking this class online, we do have good resource, and I'm helping her along the way..

However, We are stuck on this payroll program.. and need help badly..

Here is what I have and the question to the problem.
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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int numberOfEmp; 

int count = 1;
char empid[100][12];
char fname[100][14], lastname[100][15];
int hw[100];
double gp[100],  hr[100], taxrate[100], taxamt[100];
double np[100]; 
int counter = 0;
int i; 


/*All of this code in the next few lines
are just an example of I\O manipulor There are more used in later code */

//**************************************************
cout.setf(ios::right,ios::adjustfield);
cout<<setw(40)<< "Welcome!" <<"\n\n";
cout.setf(ios::right, ios::adjustfield);

cout<<" "<<setw(49)<<setfill('*')<<" ACME EBRAHIMI'S PAYROLL INSTITUE ";
cout.setf(ios::right,ios::adjustfield);
cout<<setw(50)<<setfill('*');
cout<<"\n\n Thank you for chosing this program\n";
cout<<"\nPress enter to continue.....";
cin.get(); 
//************************************************
 
cout.unsetf(ios::right); 
cout<<setfill(' ')<< setw(count); // all of this code here is just to undo the Setfill('*')
// so that thie * doesn't show in our output, at the end of our display.  

cout<<("\nThe number of Employees: ");
cin>>numberOfEmp;
 
 
// this here is the start of the main program
while((((((((((counter<numberOfEmp)&&(cout<<"Enter EMP ID")&&(cin>>empid[counter])&&(cout<<"Enter First Name")&&(cin>>fname[counter])&&(cout<<"Enter Last name")&&(cin>>lastname[counter])&&(cout<<"Enter Hours worked")&&(cin>>hw[counter])&&(cout<<"Enter the Hourly Rate")&&(cin>>hr[counter]))))))))))
counter=counter+1; 

for(i=0;i<counter;i++){
gp[i]=hw[i]*hr[i];

if(gp[i]>500)taxrate[i]=.20;
else taxrate[i]+.10;

taxamt[i]=gp[i]*taxrate[i];

np[i] = gp[i] - taxamt[i];
}//end of netpay for loop
cout <<endl;
cout<<setw(15)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
<<"LASTNAME" <<setw(4) <<"HW"<<setw(5)<<"HR"<<setw(6)
<<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NETPAY"<<endl<<endl;

for(i=0;i<counter;i++){
cin.get();
// the code setw is used for padding and to get the display to look right. 
cout<<setw(15)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]<<setw(6)<<taxamt[i]<<setw(9)
<<np[i]<<endl;   




}// end of this for loop

cout<<"Press any button to finish";
cin.get();

return 0;

}


Now here is the Question.
EX6.Sort the net pays (salary) using an array of pointers (do not change the data in the original array). For now, display only the net pays before sorting Sort the net pays (salary) using an array of pointers (do not change the data in the original array). For now, display only the net pays before sorting and after sorting.


HOW in heck do you Sort salaries by using pointers... This doesn't make sense to me.

Any help would be most wanted. Thanks
that's one heck of a while loop.

As I don't want to give you any incorrect answers or lead you astray, I can only suggest readin up on the sort in algorithm header. and/or implementing your own sort.
http://www.cplusplus.com/reference/algorithm/sort/
Last edited on
One question: why couldn't your mom post the question?
It really doesn't matter who posts the question. We both have the same question.

However, she has a few different set of people to talk to, while I have my different sets of resources to count for...

Beside all of that I have more time to post this kind of information, and I'm her tutor, she is the student.

Gcampton! Thanks for the information, that will come in handy later on... I think I know what I have to do, to make this program work.. I will post the finish source code later...
INDENT THAT code. It is already in code tags which is appreciated but the indents are necessary to see the scope.
And yeah try the algos header. It works well and you can use it on arrays.
Here is the sorting function that I found form my mom class..

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
void sortdata(string fname[], string lastname[], float netpay[], int n){
            float *p[n];
            string *f[n];
            string *l[n];

          float *temp;
          string *ftemp;
            string *ltemp;

            int sortedflag=0;
            int i, j;
            for(i=0;i<n;i++){
           p[i]=netpay+i;//initializing pointer array
            f[i]=fname+i;
            l[i]=lastname+i;}

            while(!sortedflag){
                    sortedflag=1;
                    for(j=0;j<n-1;j++){
                     if(*p[j]>*p[j+1]){
                       temp=p[j];
                       ftemp=f[j];
                       ltemp=l[j];

                       p[j]=p[j+1];
                       f[j]=f[j+1];
                       l[j]=l[j+1];

                       p[j+1]=temp;
                       f[j+1]=ftemp;
                       l[j+1]=ltemp;
                       sortedflag=0;}//SWAP
                       }//J
                       }//I

           cout<<endl<<"SORTED ARRAY: "<<endl;

           for(int i=0; i<n; i++){//loop for display
          cout<<setw(11)<<setprecision(1)<<setiosflags(ios::showpoint|ios::fixed|ios::left)
          <<*f[i]<<setw(11)<<*l[i]<<*p[i]<<endl;
            cout << ""<<endl; }
                   }//sortdata 


Now all that is left is to put it with the rest of the source code.. Can anybody give it a try before I spend all night working at it?
Topic archived. No new replies allowed.