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
|
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].totrate, EmployeeData[MAXEMPLOYEES].totreg, EmployeeData[MAXEMPLOYEES].totgross, EmployeeData[MAXEMPLOYEES].totfed, EmployeeData[MAXEMPLOYEES].totssi, EmployeeData[MAXEMPLOYEES].totnet);
printf(TOTALS2, EmployeeData[MAXEMPLOYEES].totovt, EmployeeData[MAXEMPLOYEES].totstate, EmployeeData[MAXEMPLOYEES].totdefr);
fprintf(reportFile,BREAK);
fprintf(reportFile,TOTALS1, EmployeeData[MAXEMPLOYEES].totrate, EmployeeData[MAXEMPLOYEES].totreg, EmployeeData[MAXEMPLOYEES].totgross, EmployeeData[MAXEMPLOYEES].totfed, EmployeeData[MAXEMPLOYEES].totssi, EmployeeData[MAXEMPLOYEES].totnet);
fprintf(reportFile,TOTALS2, EmployeeData[MAXEMPLOYEES].totovt, EmployeeData[MAXEMPLOYEES].totstate, EmployeeData[MAXEMPLOYEES].totdefr);
}
void printAverages(FILE *reportFile, int maxemployees, PayRecord EmployeeData[])
{
printf(AVERAGES1, (EmployeeData[MAXEMPLOYEES].totrate/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totreg/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totgross/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totfed/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totssi/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totnet/(MAXEMPLOYEES-1)));
printf(AVERAGES2, (EmployeeData[MAXEMPLOYEES].totovt/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totstate/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totdefr/(MAXEMPLOYEES-1)));
fprintf(reportFile,AVERAGES1, (EmployeeData[MAXEMPLOYEES].totrate/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totreg/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totgross/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totfed/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totssi/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totnet/(MAXEMPLOYEES-1)));
fprintf(reportFile,AVERAGES2, (EmployeeData[MAXEMPLOYEES].totovt/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totstate/(MAXEMPLOYEES-1)), (EmployeeData[MAXEMPLOYEES].totdefr/(MAXEMPLOYEES-1)));
}
float CalcFedtax(PayRecord EmployeeData[], int count) // 3.5.1
{
return (EmployeeData[count].gross - EmployeeData[count].deferred)*FEDTAXRATE;
}
float CalcStatetax(PayRecord EmployeeData[], int count) // 3.5.2
{
return EmployeeData[count].fedtax * STATETAXRATE;
}
float CalcSSItax(PayRecord EmployeeData[], int count) // 3.5.3
{
return (EmployeeData[count].gross - EmployeeData[count].deferred)*SSITAXRATE;
}
void CalculateTaxes(PayRecord EmployeeData[], int count) //3.5
{
EmployeeData[count].fedtax = CalcFedtax(EmployeeData, count); // call 3.5.1
EmployeeData[count].statetax = CalcStatetax(EmployeeData, count); // call 3.5.2
EmployeeData[count].ssitax = CalcSSItax(EmployeeData, count); // call 3.5.3
}
//====================
void printCheckHeader(PayRecord EmployeeData[], char *CheckName, int chkNo, char *refCode, int count)
{
printf(BORDER);
printf(HEADER, chkNo);
printf(BLANK);
printf(HEADER2);
printf(HEADER3);
printf(HEADER4);
printf(BLANK);
printf(BLANK);
printf(HEADER5);
printf(BLANK);
printf(HEADER6, CheckName);
printf(BLANK);
printf(HEADER7);
printf(BLANK);
printf(BLANK);
printf(HEADER8, refCode);
printf(BLANK);
printf(BLANK);
printf(BORDER);
}
void printCheckStub(PayRecord EmployeeData[], char *CheckName, int chkNo, int count)
{
printf(STUB, chkNo);
printf(BLANK);
printf(STUB2, CheckName);
printf(STUB3);
printf(STUB4);
printf(STUB5);
printf(BLANK);
printf(BLANK);
printf(BORDER);
printf("\n");
}
BOOLEAN isVowel(char aChar)
{
switch (toupper(aChar)) //<ctype.h>
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U' : return TRUE;break;
default: return FALSE;
}
}
char *generateRefCode(PayRecord EmployeeData[], int chkNo, int count)
{
static char tempStr[15+10+1];
char buffer[10+1];
int i,j = 1;
//This loop is used to clear the string everytime generateRefCode is called
for ( i = 0; i < 31; i++)
{
tempStr[i] = 0;
}
//tempStr[0] = lastname[0]; // Needs to put the first letter into the temporary string.
tempStr[0] = toupper(EmployeeData[count].LastName[0]);
// This should be the first address that holds the first letter of the last name.
// LOOP
// Need to get through all the characters in the lastname.
// Check if the letter is a vowl. If it is, add to the temporary string, else omit it.
// ENDLOOP
for (i=1; i < strlen(EmployeeData[count].LastName);i++)
{
if (!isVowel(EmployeeData[count].LastName[i]))
{
tempStr[j++] = toupper(EmployeeData[count].LastName[i]);
}
}
sprintf(buffer, "%d", chkNo);
//sprintf is used to make int chkNo into a string using a char buffer
strcat(tempStr, buffer);
tempStr[j+3] = 0;
// add string terminator, adds the the current subscript+3 because we add
// 3 numbers to the end of the string so that it adds the string terminator
// to the end of the string.
return tempStr;
}
int main(void)
{
PayRecord EmployeeData[MAXEMPLOYEES];
char FullName[15+10+1];
char CheckName[15+10+1];
char *refCode;
int count;
int chkNo = 100;
FILE *reportFile; // Read as "reportFile is a pointer to a file"
reportFile = fopen("./report.txt","wt");// open the file for "write-mode" access
if (reportFile == NULL)// Test if file DID NOT open, exit.
{
printf(" report file open failed ...\n");
fflush(stdin);
exit(-30); //reqs <stdlib.h>
}
PrintHeadings(reportFile);//Call 3.1
InitAccumulators(EmployeeData, MAXEMPLOYEES);//call 3.2
for (count = 0; count < (MAXEMPLOYEES-1); count++)
{
InputEmployeeData(EmployeeData, count);
}
QSortEmployee(EmployeeData, 0, (MAXEMPLOYEES-2));
for (count = 0; count < (MAXEMPLOYEES-1); count++)
{
strcpy(FullName, EmployeeData[count].LastName);
strcat(FullName, ", ");
strcat(FullName, EmployeeData[count].FirstName);
EmployeeData[count].gross = CalculateGross(EmployeeData, count);// Call 3.4
//CalculateHours() does not actually calculate any hours
//It seperates the hours into regular hours and overtime hours
CalculateHours(EmployeeData, count);// Call 3.4.1
CalculateTaxes(EmployeeData, count); // call 3.5
EmployeeData[count].net = CalculateNet(EmployeeData, count);//call 3.6
AddAccumulators(EmployeeData, count, MAXEMPLOYEES);//call 3.7
showReport(reportFile,FullName, EmployeeData, count);//call 3.8
}
for (count = 0; count < (MAXEMPLOYEES-1); count++)
{
refCode = generateRefCode(EmployeeData, chkNo, count);
strcpy(CheckName, EmployeeData[count].FirstName);
strcat(CheckName, " ");
strcat(CheckName, EmployeeData[count].LastName);
printCheckHeader(EmployeeData, CheckName, chkNo, refCode, count);
printCheckStub(EmployeeData, CheckName, chkNo, count);
chkNo++;
}
printTotals(reportFile, EmployeeData, MAXEMPLOYEES);//call 3.8.1
printAverages(reportFile, MAXEMPLOYEES, EmployeeData);//call 3.8.2
fclose(reportFile);// Close file
fflush(stdin);
getchar();
return 0;]
|