update: Sorting using virtual function? is it possible

void the initial post!
Last edited on
I don't understand. "Sort using class"? "Struct sort"? "Sorting both outputs together"?
Please, clarify.
I am still using dev c++. My class assignment is to create a payroll with one class by hourly wages and another using salary based wages. then sort all data. After a couple of days of racking my brain against a hard surface. I figured to use a virtual function to tie it together, but still having a headache dealing with the sort. Any nudges(big or small) would be very helpful in gaining a understanding. Also I would like to add online programming class is not fun I should of took the time to sched in a classroom enviroment. Anyway here is what code I got written. I hope I'm at least on the right track.
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
#include<iostream>
#include<fstream>
#include<iomanip>

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

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

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

void emp::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 emp::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 emp::Sort() {
      int temp;
      for (int i=0; i<n-1; i++) {
         if (np[i] > np[i+1]) {
              temp = np[i]; np[i] = np[i+1]; np[i+1] = temp;
               }
          }
	  }

void emp::sortoutput(){
  cout<<setiosflags(ios::left)<<"                                SORTED DATA"<<endl;
   for(int i=0;i<n;i++){
    cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<emp[i].fname
    <<setw(15)<<emp[i].lname<<setw(7)<<emp[i].id<<setw(4)<<setprecision(1)<<emp[i].hw
    <<setw(6)<<setprecision(2)<<emp[i].hr<<setw(5)<<emp[i].ms<<setw(5)
    <<setprecision(1)<<emp[i].oth<<setw(7)<<setprecision(2)<<emp[i].otp<<setw(9)
    <<emp[i].rgp<<setw(9)<<emp[i].gp<<setw(7)<<emp[i].tax<<setw(7)<<emp[i].np<<endl;
}
}

void payroll::printreport(){
     headings();
     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)n++;{
     yearsalgp();
     findtaxr();
     findtax();
     findnp();
     outputall();
     }
     }

void sort::printreport(){
	 Sort();
	 sortoutput();
}

//main function
int main(void){
  payroll a;
  salary b;
  sort c;
  a.printreport();
  b.printreport();
  c.printreport();
 system("pause");
}//MAIN
// function definitions
//end 
Topic archived. No new replies allowed.