Creating functions for Sorting, Edit data

For the Sorting I can't figure out how to return the Employee Numbers and Sort them in order. this is based off of user input data. I need to sort it either from Id numbers or name and I tried getting the Id one first and ran into it crashing.
I can figure out the sorting for the names if I could get the Id Numbers one working. I havn't started the Edit option yet but any advise on how to go about it would be 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
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
#include <iomanip>
# include <iostream>
using namespace std;

//Constant Identifiers
const int OverTime = 40;
const float OverTimePay = 1.5;
const int MaxSize = 10;

//Function Prototypes
void GetData(string FullNamef[], int EmployeeNumf[], float HoursWorkedf[], 
             float HourlyRatef[], int &Indexf);
void ComputePay (float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
                 float &TotalPayrollf, int Indexf);
void PrintReport (string FullNamef[], int EmployeeNumf[], float HoursWorkedf[], 
                  float HourlyRatef[], float TotalPayf[], float TotalPayrollf,
                  int Indexf);
void SortData (int EmployeeNumf[], int Indexf);

char menu();

// main body

int main()
{
string FullName[MaxSize];
int EmployeeNum[MaxSize], Index, done = 0, Temp;
float HoursWorked[MaxSize], HourlyRate[MaxSize], TotalPay[MaxSize], 
      TotalPayroll;

do
{
switch (menu())
{
   case 1:
   
      GetData(FullName, EmployeeNum, HoursWorked, 
              HourlyRate, Index);
 
   break;
              
   case 2: 
   
      ComputePay(HoursWorked, HourlyRate, TotalPay, TotalPayroll, Index);   
           
   break;
              
   case 3:
            
                                         
   break;
   
   case 4:
   
      SortData (EmployeeNum, Index);   
       
   break;
   
   case 5:
   
      PrintReport (FullName, EmployeeNum, HoursWorked, HourlyRate, TotalPay, 
                   TotalPayroll, Index);
         
   break;
   
   case 6:
        done =1;
        break;
   
   }
}while (!done);
   cout<<setw(60) << " Thanks for using Patty's Payroll Program.\n\n";
      
      system ("PAUSE");
      return 0;
} 

char menu()
{

  int Choice;
  cout<<setw(55) << "Patty's Payroll Program \n\n";
  cout<<setw(60) << "Please choose from the following \n\n\n"; 
  cout<<setw(54) << "1. Input Employee Data \n\n"; 
  cout<<setw(52) << "2. Compute Gross Pay \n\n";
  cout<<setw(53) << "3. Edit Employee Data \n\n";
  cout<<setw(56) << "4. Sort Employee Records \n\n";
  cout<<setw(47) << "5. Print Report \n\n";
  cout<<setw(39) << "6. Exit \n\n";
  cin >> Choice;
  
  return Choice;


system ("Pause");
return 0;
}

void GetData(string FullNamef[], int EmployeeNumf[], float HoursWorkedf[], 
             float HourlyRatef[], int &Indexf)
{
   Indexf = -1; 
   string Fname, Lname; 
   char Again;        
   do
   
   {
      system("CLS");
    Indexf++;             

   cout << "Please enter Your employee's  first and last name separated by a space: \t";
   cin >> Fname>>Lname;
   FullNamef[Indexf] = Fname + " " + Lname;
   cout << "Please enter Your employee's ID Number:\t";
   cin >> EmployeeNumf[Indexf];

   cout << "Please enter Your employee's Hours Worked: \t";
   cin >> HoursWorkedf[Indexf];

   cout << "Please enter Your employee's Hourly Rate:\t";
   cin >> HourlyRatef[Indexf];
   
   cout<<"Do you have another employee to process? <Y or N>\t";
    cin>> Again;  
   }while ((Again =='Y') || (Again =='y'));
return;
}

void ComputePay (float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
                 float &TotalPayrollf, int Indexf)
{
   //Local Identifiers
   TotalPayrollf = 0;
   float RegularPay, OverTimePay, DoubleTimePay;
   //computations
   for(int i=0; i<=Indexf; i++)
   {
           if (HoursWorkedf[i] <=40)
             TotalPayf[i]=HourlyRatef[i]*HoursWorkedf[i];
           else
             if (HoursWorkedf[i] <=60)
             {
                RegularPay = HourlyRatef[i]*40;
                OverTimePay = (HoursWorkedf[i]-40)*HourlyRatef[i]*1.5;
                TotalPayf[i]= RegularPay + OverTimePay;
             }
             else
             {
                RegularPay = HourlyRatef[i]*40;
                OverTimePay = HourlyRatef[i]*1.5*20;
                DoubleTimePay =(HoursWorkedf[i]-60)*HourlyRatef[i]*2;
                TotalPayf[i]= RegularPay + OverTimePay + DoubleTimePay;
             }
     TotalPayrollf += TotalPayf[i];
}
  
  
return;
}
void SortData (int EmployeeNumf[], int Indexf)
{
int i, j, first, temp;
      
      for (i= EmployeeNumf[MaxSize] - 1; i > 0; i--)
     {
           first = 0;                 // initialize to subscript of first element
           for (j=1; j<=i; j++)   // locate smallest between positions 1 and i.
          {
                 if (EmployeeNumf[j] < EmployeeNumf[first])
                 first = j;
          }
         temp = EmployeeNumf[first];   // Swap smallest found with element in position i.
         EmployeeNumf[first] = EmployeeNumf[i];
         EmployeeNumf[i] = temp;
     
     }
     return;

return;
}

void PrintReport (string FullNamef[], int EmployeeNumf[], float HoursWorkedf[], 
                  float HourlyRatef[], float TotalPayf[], float TotalPayrollf,
                  int Indexf)
{
   cout << "\n\n";
   cout << setw(48)<< "Employee Data Report";
   cout << "\n\n";
   cout << setw(5)<< "Employee's Name" << setw(13) << "Id Number"<<
           setw(17)<< "Hours Worked" << setw(17) << "Hourly Rate"<<
           setw(17)<< "Total Pay"<< endl;
   
   for(int i = 0; i <= Indexf; i++)
   { 
      
      cout<<setw(5)<<FullNamef[i]<<setw(17)<<EmployeeNumf[i]<<setw(15)
          <<HoursWorkedf[i]<<setw(17)<<HourlyRatef[i]<<setw(17)<<TotalPayf[i]
          <<cout<<endl<<fixed<<showpoint<<setprecision(2);
         
   }
   
   cout<<"\n\n Total Payroll: "<<fixed<<setprecision(2)<<TotalPayrollf<<endl;
  

return;
}  
Topic archived. No new replies allowed.