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
|
void PrintHeadings(FILE *reportFile)
{
fprintf(reportFile, HEADLINE1);
fprintf(reportFile, HEADLINE2);
fprintf(reportFile, HEADLINE3);
}
void InitAccumulators(PayRecord EmployeeData[], int maxemployees)
{
EmployeeData[MAXEMPLOYEES-1].totreg = 0;
EmployeeData[MAXEMPLOYEES-1].totovt = 0;
EmployeeData[MAXEMPLOYEES-1].totrate = 0;
EmployeeData[MAXEMPLOYEES-1].totgross = 0;
EmployeeData[MAXEMPLOYEES-1].totfed = 0;
EmployeeData[MAXEMPLOYEES-1].totstate = 0;
EmployeeData[MAXEMPLOYEES-1].totssi = 0;
EmployeeData[MAXEMPLOYEES-1].totdefr = 0;
EmployeeData[MAXEMPLOYEES-1].totnet = 0;
}
void InputEmployeeData(PayRecord EmployeeData[], int count)// 3.3
{
printf("Please enter your first and last name: ");
scanf("%s%s", EmployeeData[count].FirstName, EmployeeData[count].LastName);
printf("Please enter hours, payrate, and deferred amount: ");
scanf("%f%f%f", &EmployeeData[count].payrate, &EmployeeData[count].hours, &EmployeeData[count].deferred);
printf("\n");
}
void QSortEmployee(PayRecord EmployeeData[], int start, int finish)
{
int left = start,
right = finish;
char * pivot = EmployeeData[(start + finish) / 2].LastName;
while (left < right)
{
while ((strcmp(EmployeeData[left].LastName, pivot) < 0) && (left < right))
{
left++;
}
while ((strcmp(EmployeeData[right].LastName, pivot) > 0) && (right > left))
{
right--;
}
if (left <= right)
{
PayRecord tempEmployee = EmployeeData[left];
EmployeeData[left] = EmployeeData[right];
EmployeeData[right] = tempEmployee;
left++;
right--;
}
}
if (start < finish)
{
QSortEmployee(EmployeeData, start, right);
}
if (left < finish)
{
QSortEmployee(EmployeeData, left, finish);
}
}
float CalculateGross(PayRecord EmployeeData[], int count) // 3.4
{
return (EmployeeData[count].hours <= 40) ? EmployeeData[count].hours * EmployeeData[count].payrate :
EmployeeData[count].payrate * 40 + (EmployeeData[count].hours - 40) * 1.5 * EmployeeData[count].payrate;
}
void CalculateHours(PayRecord EmployeeData[], int count)
{
if (EmployeeData[count].hours <= 40)
{
EmployeeData[count].reghrs = EmployeeData[count].hours;
EmployeeData[count].ovthrs = 0;
}
else
{
EmployeeData[count].reghrs = 40;
EmployeeData[count].ovthrs = (EmployeeData[count].hours - 40);
}
}
float CalculateNet(PayRecord EmployeeData[], int count)
{
return EmployeeData[count].gross - (EmployeeData[count].fedtax + EmployeeData[count].statetax + EmployeeData[count].ssitax + EmployeeData[count].deferred);
}
void AddAccumulators(PayRecord EmployeeData[], int count, int maxemployees)
{
EmployeeData[MAXEMPLOYEES-1].totreg = EmployeeData[MAXEMPLOYEES-1].totreg + EmployeeData[count].reghrs;
EmployeeData[MAXEMPLOYEES-1].totovt = EmployeeData[MAXEMPLOYEES-1].totovt + EmployeeData[count].ovthrs;
EmployeeData[MAXEMPLOYEES-1].totrate = EmployeeData[MAXEMPLOYEES-1].totrate + EmployeeData[count].payrate;
EmployeeData[MAXEMPLOYEES-1].totgross = EmployeeData[MAXEMPLOYEES-1].totgross + EmployeeData[count].gross;
EmployeeData[MAXEMPLOYEES-1].totfed = EmployeeData[MAXEMPLOYEES-1].totfed + EmployeeData[count].fedtax;
EmployeeData[MAXEMPLOYEES-1].totstate = EmployeeData[MAXEMPLOYEES-1].totstate + EmployeeData[count].statetax;
EmployeeData[MAXEMPLOYEES-1].totssi = EmployeeData[MAXEMPLOYEES-1].totssi + EmployeeData[count].ssitax;
EmployeeData[MAXEMPLOYEES-1].totdefr = EmployeeData[MAXEMPLOYEES-1].totdefr + EmployeeData[count].deferred;
EmployeeData[MAXEMPLOYEES-1].totnet = EmployeeData[MAXEMPLOYEES-1].totnet + EmployeeData[count].net;
}
void showReport(FILE *reportFile, char *FullName, PayRecord EmployeeData[], int count) //3.8
{
printf(HEADLINE1);
printf(HEADLINE2);
printf(HEADLINE3);
printf(EMPLOYEEREPORT, FullName, EmployeeData[count].payrate, EmployeeData[count].reghrs, EmployeeData[count].gross, EmployeeData[count].fedtax, EmployeeData[count].ssitax, EmployeeData[count].net);
printf(EMPLOYEEREPORT2, EmployeeData[count].ovthrs, EmployeeData[count].statetax, EmployeeData[count].deferred);
fprintf(reportFile, EMPLOYEEREPORT, FullName, EmployeeData[count].payrate, EmployeeData[count].reghrs, EmployeeData[count].gross, EmployeeData[count].fedtax, EmployeeData[count].ssitax, EmployeeData[count].net);
fprintf(reportFile, EMPLOYEEREPORT2, EmployeeData[count].ovthrs, EmployeeData[count].statetax, EmployeeData[count].deferred);
}
void printTotals(FILE *reportFile, PayRecord EmployeeData[], int maxemployees)
{
printf(BREAK);
printf(TOTALS1, EmployeeData[MAXEMPLOYEES-1].totrate, EmployeeData[MAXEMPLOYEES-1].totreg, EmployeeData[MAXEMPLOYEES-1].totgross, EmployeeData[MAXEMPLOYEES-1].totfed, EmployeeData[MAXEMPLOYEES-1].totssi, EmployeeData[MAXEMPLOYEES-1].totnet);
printf(TOTALS2, EmployeeData[MAXEMPLOYEES-1].totovt, EmployeeData[MAXEMPLOYEES-1].totstate, EmployeeData[MAXEMPLOYEES-1].totdefr);
fprintf(reportFile, BREAK);
fprintf(reportFile, TOTALS1, EmployeeData[MAXEMPLOYEES-1].totrate, EmployeeData[MAXEMPLOYEES-1].totreg, EmployeeData[MAXEMPLOYEES-1].totgross, EmployeeData[MAXEMPLOYEES-1].totfed, EmployeeData[MAXEMPLOYEES-1].totssi, EmployeeData[MAXEMPLOYEES-1].totnet);
fprintf(reportFile, TOTALS2, EmployeeData[MAXEMPLOYEES-1].totovt, EmployeeData[MAXEMPLOYEES-1].totstate, EmployeeData[MAXEMPLOYEES-1].totdefr);
}
void printAverages(FILE *reportFile, int maxemployees, PayRecord EmployeeData[])
{
printf(AVERAGES1, (EmployeeData[MAXEMPLOYEES-1].totrate / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totreg / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totgross / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totfed / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totssi / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totnet / MAXEMPLOYEES));
printf(AVERAGES2, (EmployeeData[MAXEMPLOYEES-1].totovt / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totstate / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totdefr / MAXEMPLOYEES));
fprintf(reportFile, AVERAGES1, (EmployeeData[MAXEMPLOYEES-1].totrate / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totreg / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totgross / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totfed / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totssi / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totnet / MAXEMPLOYEES));
fprintf(reportFile, AVERAGES2, (EmployeeData[MAXEMPLOYEES-1].totovt / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totstate / MAXEMPLOYEES), (EmployeeData[MAXEMPLOYEES-1].totdefr / MAXEMPLOYEES));
}
|