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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
//function prototype
void GetData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf);
void ComputePay(float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
float &TotalPayrollf, int Indexf);
void EditData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf);
void SortRecord(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf);
void PrintResults(string FullNamef[],int EmployeeNumberf[],float HoursWorkedf[],
float HourlyRatef[],float TotalPayf[],
float &TotalPayrollf, int Indexf);
void exchange(float &a, float &b);
int findIndexofMin(int HoursWorkedf[], int startIndex, int endIndex);
void selSort(int HoursWorkedf[], int n);
//main body
//global constants
const int MAXSIZE = 20;
int main()
{
//local identifiers
string FullName[MAXSIZE];
int EmployeeNumber[MAXSIZE];
float HoursWorked[MAXSIZE];
float HourlyRate[MAXSIZE];
float TotalPay[MAXSIZE];
float TotalPayroll = 0.0;
int Index = 0;
int DesignCode;
char Another='y';
int choice;
int menu();
//input module
cout<<setw(17)<<"Patty's Payroll Program\n";
cout<<endl;
cout<<setw(17)<<"Please choose from the following:\n";
cout<<"\t\t\n";
cout<<setw(19)<<" 1. "<<"Input Employee Data\n";
cout<<setw(19)<<" 2. "<<"Compute Gross Pay\n";
cout<<setw(19)<<" 3. "<<"Edit Employee Data\n";
cout<<setw(19)<<" 4. "<<"Sort Employee Data\n";
cout<<setw(19)<<" 5. "<<"Print Report\n";
cout<<setw(19)<<" 6. "<<"Exit\n";
cin>>choice;
do
{
DesignCode=menu();
switch(DesignCode)
{
case 1://GET DATA
GetData(FullName, EmployeeNumber, HoursWorked, HourlyRate, Index);
break;
case 2://GROSS PAY
ComputePay(HoursWorked, HourlyRate, TotalPay, TotalPayroll, Index);
break;
case 3://EDIT EMPLOYEE DATA
break;
case 4://SORT
break;
case 5://PRINT REPORT
//PrintResults(FullName, EmployeeNumber, HoursWorked,
// HourlyRate, TotalPayroll, Index);
break;
case 6://EXIT
cout<<"Thank you very much...GOODBYE....!!!"<<endl;
}//end of switch
cout<<endl;
}while((Another=='Y')||(Another=='y'));
return 1;
}//end of program
//function defination
void GetData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf)
{
string FirstName, LastName, FullName;
char Another;
do
{
cout<<"Please enter your first and last name separated by a space?\n";
cin >> FirstName >> LastName;
FullName = FirstName + " " + LastName;
FullNamef[Indexf] = FullName;
cout<<"Please enter your four digit Employee Number?\n";
cin>>EmployeeNumberf[Indexf];
cout<<"How many hours did you work last week?\n";
cin>>HoursWorkedf[Indexf];
cout<<"What is your hourly rate?\n";
cin>>HourlyRatef[Indexf];
cout<<"Do you have another employee to process<Y or N>?\t";
cin>>Another;
if((Another=='Y')||(Another=='y'))
{
system("PAUSE");
system("CLS");
}//end of if
}while((Another=='Y')||(Another=='y'));
//end of while
return;
}
void ComputePay(float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
float &TotalPayrollf, int Indexf)
{
//Local Identifiers
TotalPayrollf = 0;
float RegularPay, OverTimePay, DoubleTimePay;
char choice;
//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 EditData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf)
{
//local identifiers
string FirstName, LastName, FullName;
string NFirstName, NLastName, NFullName;
int EmployeeNumberf;
int NEmployeeNumber;
float HoursWorkedf;
float NHoursWorked;
float HourlyRatef;
float NHourlyRate;
int choice;
cout<<"Please enter the Employee ID of the employee whose information you wish to change: ";
// string EmployIdNumber2 = to_string(EmployIdNumber);
cin>>EmployeeIdNumberf;
cout<<"Please chose from the following selection to edit:"<<endl;
cout<<" 1. "<<"Employee Name\n";
cout<<" 2. "<<"Employee Id Number\n";
cout<<" 3. "<<"Hours Worked\n";
cout<<" 4. "<<"Hourly Rate\n";
cin>>choice;
int choice;
switch(choice)
{
case '1':
cout<<"Please input new first and last Name of the employee?\n";
cin >> NFirstName >> NLastName;
NFullName = NFirstName + " " + NLastName;
NFullName[Index] = NFullName;
case '2':
cout<<"Please enter your four digit Employee Number?\n";
cin>>NEmployeeNumber[Index];
case '3':
cout<<"How many hours did you work last week?\n";
cin>>NHoursWorked[Index];
case '4':
cout<<"What is your hourly rate?\n";
cin>>NHourlyRate[Index];
cout<<"Do you have another employee to process<Y or N>?\t";
cin>>Another;
if((Another=='Y')||(Another=='y'))
{
system("PAUSE");
system("CLS");
}//end of if
}while((Another=='Y')||(Another=='y'));
}
return;
void PrintResults(string FullNamef[],int EmployeeNumberf[],float HoursWorkedf[],
float HourlyRatef[],float TotalPayf[],
float &TotalPayrollf, int Indexf)
{
//local identifiers
float RegularPay, OverTimePay, DoubleTimePay;
int Index;
cout<<setw(45)<<"-PAYROLL REPORT-"<<endl;
cout<<"---------------------------------------------------"<<endl;
cout<<setw(45)<<Indexf<<setw(42)<<FullNamef[Indexf]<<setw(35)<<EmployeeNumberf[Indexf]<<setw(31)
<<HoursWorkedf[Indexf]<<setw(28)<<HourlyRatef[Indexf]<<setw(21)<<RegularPay<<setw(15)
<<OverTimePay<<setw(12)<<DoubleTimePay<<setw(8)<<TotalPayf[Indexf]<<setw(5)
<<TotalPayrollf;
for(int i=0; i<Indexf; i++)
{
cout<<i+1<<setw(45)<<endl;
}
return;
}
void exchange(int &a, int &b)
{
float temp;
temp = a;
a = b;
b = temp;
return;
}
int findIndexofMin(int HoursWorkedf[], int startIndex, int endIndex)
{
//local data
int minIndex;
int i;
if((startIndex < 0)||(startIndex > endIndex))
{
cerr<<"Error in subarray bounds"<<endl;
return -1;
}
minIndex = startIndex;
for(i=startIndex+1; i<= endIndex; i++)
if(items[i]<items[minIndex])
minIndex=i;
return minIndex;
}//end of findIndexofMin
void selSort(int HoursWorked[], int n)
{
//local data
int minSub;
for(int i = 0; i < n-1; i++)
{
minSub = findIndexofMin(HoursWorked, i, n-1);
exchange(HoursWorked[minSub], HoursWorked[i]);
}
}//end of function;
|