I know where the problem is just dont know how to fix it.{still in need}

I've been trying to figure out how to conduct a merge sort and been having problems Here is my code with out the sort and it works fine. If some can give me a hand in understanding the merge sort would be greatly appreciated.
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
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;
 //declaration of variables
 class emp{
public: int id, hw, oth;
  float hr, otp, rgp, gp, tax, np, TAXR;
  char fname[15], lname[15], ms;
  void findgp();
  void findtaxr();
  void findtax();
  void findnp();
  void headings();
  void outputall();};//STRUCT
 class hourly: public emp{
   public: void findovt();
         hourly();
         ~hourly();         
         void printreport(); };
 class salary: public emp{
  public: float yearsal;
  void yearsalgp();
  salary();
  ~salary();
 void printreport(); };

hourly::hourly(){
   ifstream fin("payrollfl.txt");}
   hourly::~hourly(){
   ifstream fin();}

salary::salary(){
   ifstream fin("sal.txt");}
   salary::~salary(){
   ifstream fin();}



void hourly::findovt(){
      if(hw>40){
      oth=hw-40;
      otp=oth*hr*1.5;
      rgp=hw*hr;
    }//IF
    else{
     oth=0;
     otp=0;
     rgp=hw*hr;
    }//ELSE
}//FINDOVT

void salary::yearsalgp(){
  hw=40;
  hr=(yearsal/52)/40;
  rgp=hr*40;
  gp=rgp+otp;
  oth=0;
  otp=0;
  }

void emp::findgp(){
    gp=rgp+otp;
}//FINDGP


void emp::findtaxr(){
   if ((gp>1000) && (ms=='S'||ms=='s')) TAXR=0.35;
   else if ((gp>1000) && (ms=='M'||ms=='m')) TAXR=0.30;
   else if ((gp>1000) && (ms=='H'||ms=='h')) TAXR=0.25;
   else if ((gp>800) && (ms=='S'||ms=='s')) TAXR=0.25;
   else if ((gp>800) && (ms=='M'||ms=='m')) TAXR=0.20;
   else if ((gp>800) && (ms=='H'||ms=='H')) TAXR=0.15;
   else if ((gp>500) && (ms=='S'||ms=='s')) TAXR=0.15;
   else if ((gp>500) && (ms=='M'||ms=='m')) TAXR=0.10;
   else if ((gp>500) && (ms=='H'||ms=='h')) TAXR=0.05;
   else TAXR=0.0;
}//FINDTAXR

void emp::findtax(){
     tax=gp*TAXR;
}//FINDTAX

void emp::findnp(){
     np=gp-tax;
}//FINDNP

void emp::headings(){
    cout<<setiosflags(ios::left)<<"                                Digdug's
National Bank"<<endl;
    cout<<setiosflags(ios::left)<<"     (Employee id 5000 series hourly
employees, 4000 series are salary based employees)"<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME"<<setw(15)
<<"LAST NAME"<<setw(7)<<"EMP ID"<<setw(4)<<"HW"<<setw(6)<<"HR"
<<setw(5)<<"STAT"<<setw(5)<<"OTH"<<setw(7)<<"OTP"<<setw(7)<<"REGP"
<<setw(9)<<"GROSS"<<setw(7)<<"TAX"<<setw(7)<<"NET"<<endl<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"=============="<<setw(15)
<<"=============="<<setw(7)<<"======"<<setw(4)<<"==="<<setw(6)<<"====="
<<setw(5)<<"===="<<setw(5)<<"==="<<setw(7)<<"======"<<setw(7)<<"======"
<<setw(9)<<"========"<<setw(7)<<"======"<<setw(7)<<"======"<<endl;
}


void emp::outputall(){
  cout<<fixed;
   cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL

void hourly::printreport(){
     int i=0;
     headings();
     ifstream fin("payrollfl.txt");
     while(fin>>fname>>lname>>id>>hw>>hr>>ms){
     findovt();
     findgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     i++;}
}

void salary::printreport(){
     int i=0;
     ifstream fin("sal.txt");
     while(fin>>fname>>lname>>id>>yearsal>>ms){
     yearsalgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     i++;}
     }


//main function
int main(void){
  hourly a;
  salary b;
  a.printreport();
  b.printreport();
 system("pause");
}//MAIN 
// function definitions
//end  
Last edited on
Merge sort is a "devide-and-conquer" algorithm. The idea is based on the fact that some problems (including sorting) become easier when they are applied to shorter sequences.

Suppose you have two sorted sequences, how do you "merge" them into one sorted sequence?

All you have to do now is to create "short" sorted sequences. A sequence of one element is always sorted. So, basically, what you do is:
- Divide (...until every part is sorted)
- Merge (every sorted piece into a larger piece)

This is usually done recursively:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
mergesort(sequence s)
{
 if(size > 1)
 {
   mergesort(s.first_half);
   mergesort(s.second_half);
   merge(s.first_half /*which is now sorted*/, s.second_half /*which is also sorted*/);
 }
/* else: s is sorted... */
}
merge(sequence s1, sequence s2)
{
//... you know what to do here...
}

I have posted vague pseudocode, because I think that if you want to understand the algorithm, you should implement (and think about it) yourself. If you just want a copy&paste solution, use std::stable_sort instead.

Edit:
Argh, wrote "mergesort" in the declaration and "sort" in the body. Of course, it should be recursive...
Last edited on
Thank you for the fast response. Ive tried something like once and had no joy. I will give it another shot though.
here is an update on where I stand. Im trying to get the each class data sorted first before I implement a merge sort. but no joy on my result. Here is my current code with errors I am recieving. any Nudges would be appricated.
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
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;
 //declaration of variables
 class emp{
public: int id, hw, oth;
  float hr, otp, rgp, gp, tax, np, TAXR;
  char fname[15], lname[15], ms;
  void findgp();
  void findtaxr();
  void findtax();
  void findnp();
  void headings();
  void outputall();};//STRUCT
 class hourly: public emp{
   public: int n;
         void findovt();
         void sSort();
         hourly();
         ~hourly();
         void printreport(); };
 class salary: public emp{
  public: int m;
  float yearsal;
  void yearsalgp();
  void sSort();
  salary();
  ~salary();
 void printreport(); };

hourly::hourly(){
   ifstream fin("payrollfl.txt");}
   hourly::~hourly(){
   ifstream fin();}

salary::salary(){
   ifstream fin("sal.txt");}
   salary::~salary(){
   ifstream fin();}



void hourly::findovt(){
      if(hw>40){
      oth=hw-40;
      otp=oth*hr*1.5;
      rgp=hw*hr;
    }//IF
    else{
     oth=0;
     otp=0;
     rgp=hw*hr;
    }//ELSE
}//FINDOVT

void salary::yearsalgp(){
  hw=40;
  hr=(yearsal/52)/40;
  rgp=hr*40;
  gp=rgp+otp;
  oth=0;
  otp=0;
  }

void emp::findgp(){
    gp=rgp+otp;
}//FINDGP


void emp::findtaxr(){
   if ((gp>1000) && (ms=='S'||ms=='s')) TAXR=0.35;
   else if ((gp>1000) && (ms=='M'||ms=='m')) TAXR=0.30;
   else if ((gp>1000) && (ms=='H'||ms=='h')) TAXR=0.25;
   else if ((gp>800) && (ms=='S'||ms=='s')) TAXR=0.25;
   else if ((gp>800) && (ms=='M'||ms=='m')) TAXR=0.20;
   else if ((gp>800) && (ms=='H'||ms=='H')) TAXR=0.15;
   else if ((gp>500) && (ms=='S'||ms=='s')) TAXR=0.15;
   else if ((gp>500) && (ms=='M'||ms=='m')) TAXR=0.10;
   else if ((gp>500) && (ms=='H'||ms=='h')) TAXR=0.05;
   else TAXR=0.0;
}//FINDTAXR

void emp::findtax(){
     tax=gp*TAXR;
}//FINDTAX

void emp::findnp(){
     np=gp-tax;
}//FINDNP

void emp::headings(){
    cout<<setiosflags(ios::left)<<"                                Digdug's National 
Bank"<<endl;
    cout<<setiosflags(ios::left)<<"     (Employee id 5000 series hourly
 employees, 4000 series are salary based employees)"<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME"<<setw(15)
<<"LAST NAME"<<setw(7)<<"EMP ID"<<setw(4)<<"HW"<<setw(6)
<<"HR"<<setw(5)<<"STAT"<<setw(5)<<"OTH"<<setw(7)<<"OTP"
<<setw(7)<<"REGP"<<setw(9)<<"GROSS"<<setw(7)<<"TAX"
<<setw(7)<<"NET"<<endl<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"=============="
<<setw(15)<<"=============="<<setw(7)<<"======"
<<setw(4)<<"==="<<setw(6)<<"====="<<setw(5)<<"===="
<<setw(5)<<"==="<<setw(7)<<"======"<<setw(7)<<"======"
<<setw(9)<<"========"<<setw(7)<<"======"<<setw(7)
<<"======"<<endl;
}


void emp::outputall(){
  cout<<fixed;
   cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL

void hourly::sSort(){
        int temp;
        for (int i=0; i<n-1; i++) {
            if (np[i] > np[i+1]){
                temp = hourly->i; hourly[i] = hourly[i+1]; hourly[i+1] = temp;
             }
        }
}

void salary::sSort(){
        int temp;
        for (int i=0; i<m-1; i++) {
            if (np[i] > np[i+1]){
                temp = salary[i]; salary[i] = salary[i+1]; salary[i+1] = temp;
             }
        }
}

void hourly::printreport(){
     int i=0;
     int n=0;
     headings();
     ifstream fin("payrollfl.txt");
     while(fin>>fname>>lname>>id>>hw>>hr>>ms)n++;{
     findovt();
     findgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     sSort();
     outputall();
     i++;}
}

void salary::printreport(){
     int i=0;
     ifstream fin("sal.txt");
     while(fin>>fname>>lname>>id>>yearsal>>ms)m++;{
     yearsalgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     sSort();
     outputall();
     i++;}
     }


//main function
int main(void){
  hourly a;
  salary b;
  a.printreport();
  b.printreport();
 system("pause");
}//MAIN 
// function definitions
//end  


The error I am recieving is both sSorts function. "expected primary-expression before '[' token"
Anyone know what I am doing wrong.
hourly::sSort()
What in God's name is this? This is no sort. And definitely not merge sort.
This is a sort i use in a previous program using struct instead of class. I'm trying to sort the data first before I implemet the the merge sort. Is there a better way?
That is not a sort. It is the inner loop of a bubble sort, but that code you have there will not sort the array.

http://en.wikipedia.org/wiki/Bubble_sort
I ve tried it still no joy. here is the code. Anyone else have any idea.
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
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;
 //declaration of variables
 class emp{
public: int id, hw, oth;
  float hr, otp, rgp, gp, tax, np, TAXR;
  char fname[15], lname[15], ms;
  void findgp();
  void findtaxr();
  void findtax();
  void findnp();
  void headings();
  void outputall();};//STRUCT
 class hourly: public emp{
   public:          int n;
         void findovt();
         void sSort();
         hourly();
         ~hourly();
         void printreport(); };
 class salary: public emp{
  public: int m;
  float yearsal;
  void yearsalgp();
  void sSort();
  salary();
  ~salary();
 void printreport(); };

hourly::hourly(){
   ifstream fin("payrollfl.txt");}
   const int MAX=100;
   hourly hou[MAX];
   hourly::~hourly(){
   ifstream fin();}

salary::salary(){
   ifstream fin("sal.txt");}
   const int SIZE=100;
   salary sal[MAX];
   salary::~salary(){
   ifstream fin();}



void hourly::findovt(){
      if(hw>40){
      oth=hw-40;
      otp=oth*hr*1.5;
      rgp=hw*hr;
    }//IF
    else{
     oth=0;
     otp=0;
     rgp=hw*hr;
    }//ELSE
}//FINDOVT

void salary::yearsalgp(){
  hw=40;
  hr=(yearsal/52)/40;
  rgp=hr*40;
  gp=rgp+otp;
  oth=0;
  otp=0;
  }

void emp::findgp(){
    gp=rgp+otp;
}//FINDGP


void emp::findtaxr(){
   if ((gp>1000) && (ms=='S'||ms=='s')) TAXR=0.35;
   else if ((gp>1000) && (ms=='M'||ms=='m')) TAXR=0.30;
   else if ((gp>1000) && (ms=='H'||ms=='h')) TAXR=0.25;
   else if ((gp>800) && (ms=='S'||ms=='s')) TAXR=0.25;
   else if ((gp>800) && (ms=='M'||ms=='m')) TAXR=0.20;
   else if ((gp>800) && (ms=='H'||ms=='H')) TAXR=0.15;
   else if ((gp>500) && (ms=='S'||ms=='s')) TAXR=0.15;
   else if ((gp>500) && (ms=='M'||ms=='m')) TAXR=0.10;
   else if ((gp>500) && (ms=='H'||ms=='h')) TAXR=0.05;
   else TAXR=0.0;
}//FINDTAXR

void emp::findtax(){
     tax=gp*TAXR;
}//FINDTAX

void emp::findnp(){
     np=gp-tax;
}//FINDNP

void emp::headings(){
    cout<<setiosflags(ios::left)<<"                                Digdug's National 
Bank"<<endl;
    cout<<setiosflags(ios::left)<<"     (Employee id 5000 series hourly 
employees, 4000 series are salary based employees)"<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME"<<setw(15)
<<"LAST NAME"<<setw(7)<<"EMP ID"<<setw(4)<<"HW"<<setw(6)
<<"HR"<<setw(5)<<"STAT"<<setw(5)<<"OTH"<<setw(7)<<"OTP"<<setw(7)
<<"REGP"<<setw(9)<<"GROSS"<<setw(7)<<"TAX"<<setw(7)
<<"NET"<<endl<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"=============="<<setw(15)
<<"=============="<<setw(7)<<"======"<<setw(4)<<"==="<<setw(6)
<<"====="<<setw(5)<<"===="<<setw(5)<<"==="<<setw(7)
<<"======"<<setw(7)<<"======"<<setw(9)<<"========"<<setw(7)
<<"======"<<setw(7)<<"======"<<endl;
}


void emp::outputall(){
  cout<<fixed;
   cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL

void hourly::sSort(){
        for (int i=0; i<n-1; i++) {
         if (hou[i].np> hou[i+1].np)
             swap(hou[i], hou[i+1]);
             }
       }


void salary::sSort(){
        for (int i=0; i<m-1; i++) {
         if (sal[i].np> sal[i+1].np)
             swap(sal[i], sal[i+1]);
        }
}
void hourly::printreport(){
     int i=0;
     headings();
     ifstream fin("payrollfl.txt");
     while(fin>>hou[n].fname>>hou[n].lname>>hou[n].id>>hou[n].hw>>hou[n].hr>>hou[n].ms)n++;{
     findovt();
     findgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     sSort();
     outputall();
     i++;}
}

void salary::printreport(){
     int i=0;
     ifstream fin("sal.txt");
     while(fin>>sal[m].fname>>sal[m].lname>>sal[m].id>>sal[m].yearsal>>sal[m].ms)m++;{
     yearsalgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     sSort();
     outputall();
     i++;}
     }


//main function
int main(void){
  hourly a;
  salary b;
  a.printreport();
  b.printreport();
 system("pause");
}//MAIN 
// function definitions
//end  
Last edited on
I don't really understand why you're trying to implement a bubble sort if what you really want is a merge sort. Furthermore, I don't know how you will implement merge if bubble is giving you trouble:
1
2
3
4
5
6
void hourly::sSort(){
	for (int i=0; i<n-1; i++){
		if (hou[i ].np> hou[i+1].np)
			swap(hou[i ], hou[i+1]);
	}
}

Line 1: sorts of a particular kind should at least take a pointer to the array they're going to sort.
Line 4: There is is no defined swap() function in C++ (well, there may be one, but I don't really know), you have to define it yourself.
Line 2: I see from the above that you did read the article, but not enough to see that the bubble sort in it uses two nested loops.

This is what a properly written bubble sort looks like. Looks like. Just copying this code will not do, in your case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typedef unsigned long ulong;

template <typename T>
void swap(T *A,T *B){
	T temp=*A;
	*A=*B;
	*B=temp;
}

template <typename T>
void bubblesort(T *arr,ulong start,ulong end){
	bool swapped=1;
	while (swapped){
		swapped=0;
		for (ulong b=0;b<end;b++){
			if (arr[b]>arr[b+1]){
				swap(arr+b,arr+b+1);
				swapped=1;
			}
		}
	}
}
The problem is not in the sort. Yes the sort works I know I ve used it before. The problem is Its not saving the data our every time it spits it out it atou write over it with the next data so in reality its only sorting one data which does n't work. If I can please get a Big nudge on how to fix this would be appreciated as I really have no idea what I am doing on this subject. here is my 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
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
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
using namespace std;
 //declaration of variables
 class emp{
public: string id;
  int n, m, hw, oth, indexOfMin;
  float hr, otp, rgp, gp, tax, np, TAXR;
  char fname[15], lname[15], ms;
  virtual double findgp();
  virtual double findtaxr();
  virtual double findtax();
  virtual double findnp();
  void headings();
  void start(); };//STRUCT
 class hourly: virtual public emp{
      public: double findovt(){
       if(hw>40){
        oth=hw-40;
        otp=oth*hr*1.5;
        rgp=hw*hr;
        }//IF
       else{
       oth=0;
       otp=0;
       rgp=hw*hr;
       }
       }
         void sSort();
         void outputall();
         void soutputall();
      public:
          hourly();
         ~hourly();
         void printreport();
         void finished(); };
 class salary: virtual public emp{
  int m;
  float yearsal;
  void yearsalgp();
  void sSort();
  void outputall();
  void soutputall();
public:
  salary();
  ~salary();
  void printreport();
  void finished(); };

hourly::hourly(){
   ifstream fin("payrollfl.txt");}
   const int MAX=100;
   hourly hou[MAX];
   hourly::~hourly(){
   ifstream fin();}

salary::salary(){
   ifstream fin("sal.txt");}
   const int SIZE=100;
   salary sal[SIZE];
   salary::~salary(){
   ifstream fin();}

void salary::yearsalgp(){
  hw=40;
  hr=(yearsal/52)/40;
  rgp=hr*40;
  gp=rgp+otp;
  oth=0;
  otp=0;
  }

double emp::findgp(){
    gp=rgp+otp;
    return gp;
}//FINDGP


double emp::findtaxr(){
   if ((gp>1000) && (ms=='S'||ms=='s')) TAXR=0.35;
   else if ((gp>1000) && (ms=='M'||ms=='m')) TAXR=0.30;
   else if ((gp>1000) && (ms=='H'||ms=='h')) TAXR=0.25;
   else if ((gp>800) && (ms=='S'||ms=='s')) TAXR=0.25;
   else if ((gp>800) && (ms=='M'||ms=='m')) TAXR=0.20;
   else if ((gp>800) && (ms=='H'||ms=='H')) TAXR=0.15;
   else if ((gp>500) && (ms=='S'||ms=='s')) TAXR=0.15;
   else if ((gp>500) && (ms=='M'||ms=='m')) TAXR=0.10;
   else if ((gp>500) && (ms=='H'||ms=='h')) TAXR=0.05;
   else TAXR=0.0;
   return TAXR;
}//FINDTAXR

double emp::findtax(){
     tax=gp*TAXR;
     return tax;
}//FINDTAX

double emp::findnp(){
     np=gp-tax;
     return np;
}//FINDNP

void emp::headings(){
    cout<<setiosflags(ios::left)<<"                                Digdug's National 
Bank"<<endl;
    cout<<setiosflags(ios::left)<<"     (Employee id 5000 series hourly 
employees, 4000 series are salary based employees)"<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME"<<setw(15)
<<"LAST NAME"<<setw(7)<<"EMP ID"<<setw(4)<<"HW"<<setw(6)
<<"HR"<<setw(5)<<"STAT"<<setw(5)<<"OTH"<<setw(7)<<"OTP"
<<setw(7)<<"REGP"<<setw(9)<<"GROSS"<<setw(7)<<"TAX"
<<setw(7)<<"NET"<<endl<<endl;
  cout<<setiosflags(ios::left)<<setw(15)<<"=============="
<<setw(15)<<"=============="<<setw(7)<<"======"
<<setw(4)<<"==="<<setw(6)<<"====="<<setw(5)<<"===="
<<setw(5)<<"==="<<setw(7)<<"======"<<setw(7)<<"======"
<<setw(9)<<"========"<<setw(7)<<"======"<<setw(7)
<<"======"<<endl;
}

void hourly::outputall(){
  cout<<fixed;
     cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL

void salary::outputall(){
  cout<<fixed;
     cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL
void hourly::soutputall(){
 cout<<fixed;
   for(int i=0;i<5;i++){
   cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL
}
void salary::soutputall(){
 cout<<fixed;
   for(int i=0;i<5;i++){
   cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
       <<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
       <<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
       <<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
       <<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL
}
void hourly::sSort(){
        for (int i=0; i<5-1; i++) {
            if (hou[i].np > hou[i+1].np) {
                hourly temp = hou[i]; hou[i] = hou[i+1]; hou[i+1] = temp;
             }
        }
}


void salary::sSort(){
        for (int i=0; i<5-1; i++) {
            if (sal[i].np > sal[i+1].np) {
                salary temp = sal[i]; sal[i] = sal[i+1]; sal[i+1] = temp;
             }
        }
}

void emp::start(){
     headings();
     }

void hourly::printreport(){
     n=0;
     ifstream fin("payrollfl.txt");
     while(fin>>fname>>lname>>id>>hw>>hr>>ms)n++;{
     findovt();
     findgp();
     findtaxr();
     findtax();
     findnp();}
     outputall();
}
void salary::printreport(){
     ifstream fin("sal.txt");
     while(fin>>fname>>lname>>id>>yearsal>>ms){
     yearsalgp();
     findtaxr();
     findtax();
     findnp();
     outputall();}
}

void hourly::finished(){ 
     sSort();
     soutputall();}

void salary::finished(){ 
     sSort();
     soutputall();}

//main function
int main(void){
  emp a;
  hourly b;
  salary c;
  a.start();
  b.printreport();
  c.printreport();
  b.finished();
  c.finished();
 system("pause");
}//MAIN 
// function definitions
//end   
I don't really understand what you're saying. If you could maybe rephrase it to make it clearer, then I might be able to help you. Also, put some comments on the code to help identify the problematic section.
The problem is Its not saving the data our
Where? In which part of the code?
every time it spits it out it atou write over it with the next data
???
so in reality its only sorting one data which does n't work.
Oh, you mean the sort I assured you doesn't work, doesn't work? What a surprise!

And don't post the entire program every time. It's just annoying and doesn't help much. If you must, there are plenty of places online where you can upload text to link to others. Maybe someone else can help me with their name?
Yes the sort does work. I ve used those sorts in previous programs and they work fine. the problem is in the inheritence I guess. I've been wondering if it might be the deconstructer problem . sorry mispell atou meant to be auto. The first time the data runs through the programm and gets output is fine. after that, only the last data is there, for instance each class has 5 groups of array. but only the last one saves to continue through the rest of the program. any ideas would help.
Topic archived. No new replies allowed.