Вы находитесь на странице: 1из 14

a) Hierarchy chart

3.0 Payroll
3.1 printReportHeadings();
3.2 initializeAccumulators(inout totFedTax as real, inout totStateTax as real, inout totGross as real,
inout totHours as real, inout totPayRate as real, inout totDeferred as real,
inout totOvertimeHours as real);
3.3 inputEmployeeData (out lastName as string, out firstName as string, out hours as real,
out payRate as real, out deferred as real);
3.4 calculateGross(in hours as real, in payrate as real, out gross as real);
3.5 calculateTaxes(in gross as real, in deferred as real, out fedTax as real,
out stateTax as real, out ssiTax as real);
3.5.1 calcFedTax(in gross as real, in deferred as real, out fedTax);
3.5.2 calcStateTax(in fedTax as real, out stateTax);
3.5.3 ccalcSSITax( in gross as float, in float as deferred, out ssiTax);
3.6 calcNetPay(in gross as real, in fedTax as real, in stateTax asreal, in ssiTax as real, out netPay as real);
3.7 calcRegularHours(in hours as real, out regularHours as real);
3.8 calcOvertimeHours(in hours as real, out overtimeHours as real);
3.9 printEmployeeData(in reportFile, in lastName as string, in firstName as string, in hours as real,
in payRate as real, in gross as real, in deferred as real, in fedTax as real, in stateTax as real,
in ssiTax as real);
3.10 addDetailsToAccumulator(inout totFedTax as real,inout totStateTax as real, inout totGross as real,
ionut totHours as real, inout totPayRate as real, inout totDeferred as real, inout totOvertimeHours as real,
in fedTax as real, in stateTax as real, in ssiTax as real, in gross as real, in hours as real,
in payRate as real, in deferred as real, in regularHours as real, in overtimeHours as real);
3.11 addEmployee(out answer as boolean);
3.12 printSummaryReport(in reportFile, in totFedTax as real, in totStateTax as real,in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);
3.12.1 printTotal(in reportFile, in totFedTax as real, in totStateTax as real, in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);
3.12.2 printAverage(in reportFile, in totFedTax as real, in totStateTax as real, in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);

b) flowchart

c) Program source and header files list


main2.cpp
calculateTaxes.cpp
employeeRecord.h
============================================ main2.cpp===========================================
/*
Program: Assignment 2B
Author: Josue Herrera
Date: 07/01/2015
Software Change Record
Date Who What
07/01 Josue Begin program
07/02 Josue Add remaining outlined functions
07/04 Josue Simplify function and reduce size of the main function by by creating an array for totals
07/06 Josue Split printSummaryReport(7.9) into printTotal(7.9.1) and printAverage(7.9.2)
07/08 Josue Create fullName char array to display name correctly
07/09 Josue Fix REPFORMATX to display results correctly
07/16 Josue Fix in/out interference in hi-chart and add use of inout
Add addEmployee as boolean to ask user if he wishes to add an employee
Change total constants to enumerated types
Change variables lastName and firstName from charcters to string in hi-chart
Add functions 3.5.1, 3.5.2 and 3.5.3 to hi-chart
07/20 Josue Create the data structure and save it to employeeRecord.h
Change parameters and arguments to include the data structure from the file employeeRecord.h
Create calcNetPay, calcRegularHours and calcOvertimeHours function
3.0 Payroll
3.1 printReportHeadings();
3.2 initializeAccumulators(inout totFedTax as real, inout totStateTax as real, inout totGross as real,
inout totHours as real, inout totPayRate as real, inout totDeferred as real,
inout totOvertimeHours as real);
3.3 inputEmployeeData (out lastName as string, out firstName as string, out hours as real,
out payRate as real, out deferred as real);
3.4 calculateGross(in hours as real, in payrate as real, out gross as real);
3.5 calculateTaxes(in gross as real, in deferred as real, out fedTax as real,
out stateTax as real, out ssiTax as real);

3.5.1 calcFedTax(in gross as real, in deferred as real, out fedTax);


3.5.2 calcStateTax(in fedTax as real, out stateTax);
3.5.3 ccalcSSITax( in gross as float, in float as deferred, out ssiTax);
3.6 calcNetPay(in gross as real, in fedTax as real, in stateTax asreal, in ssiTax as real, out netPay as real);
3.7 calcRegularHours(in hours as real, out regularHours as real);
3.8 calcOvertimeHours(in hours as real, out overtimeHours as real);
3.9 printEmployeeData(in reportFile, in lastName as string, in firstName as string, in hours as real,
in payRate as real, in gross as real, in deferred as real, in fedTax as real, in stateTax as real,
in ssiTax as real);
3.10 addDetailsToAccumulator(inout totFedTax as real,inout totStateTax as real, inout totGross as real,
ionut totHours as real, inout totPayRate as real, inout totDeferred as real, inout totOvertimeHours as real,
in fedTax as real, in stateTax as real, in ssiTax as real, in gross as real, in hours as real,
in payRate as real, in deferred as real, in regularHours as real, in overtimeHours as real);
3.11 addEmployee(out answer as boolean);
3.12 printSummaryReport(in reportFile, in totFedTax as real, in totStateTax as real,in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);
3.12.1 printTotal(in reportFile, in totFedTax as real, in totStateTax as real, in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);
3.12.2 printAverage(in reportFile, in totFedTax as real, in totStateTax as real, in totGross as real,
in totHours as real, in totPayRate as real, in totDeferred as real, in totOvertimeHours as real);
*/
#include <stdio.h>
#include <string.h>
#include "employeeRecord.h"
#define
#define
#define
#define
#define
#define

REPLINEA " Employee


Payrate RegHours Gross
Fed
SSI
Net \n"
REPLINEB " Name
OvtHours Pay
State Defr
Pay \n"
REPLINEC " ========
======= ======== ======== ===== =====
REPFORMATA " %-20s%7.2f%12.2f%11.2f%10.2f%10.2f%10.2f\n"
REPFORMATB " %39.2f%21.2f%10.2f\n"
REPFORMATC " %-20s%7.2f%12.2f%11.2f%10.2f%10.2f%10.2f\n"

====== \n"

enum totalsList {FEDTAX, STATETAX, SSITAX, GROSS, HOURS, PAYRATE, DEFERRED, REGULARHOURS, OVERTIMEHOURS,
EMPLOYEES,NETPAY,TOTALS};

void printReportHeadings(FILE * reportFile); // 3.1


void initializeAccumulators(float total[]); //3.2
void inputEmployeeData(employeeRecord &employeeData); // 3.3
float calculateGross(employeeRecord &employeeData); // 3.4
extern void calculateTaxes(employeeRecord &employeeData); // 3.5
void calcNetPay(employeeRecord &employeeData); // 3.6
void calcRegularHours(employeeRecord &employeeData); // 3.7
void calcOvertimeHours(employeeRecord &employeeData); // 3.8
void printEmployeeData(FILE *reportFile,employeeRecord &employeeData); // 3.9
void addDetailsToAccumulator(float total[], employeeRecord &employeeData); //3.10
bool addEmployeeAnsw(); // 3.11
void printSummaryReport(FILE * reportFile,float total[]); // 3.12
void printTotal(FILE *reportFile, float total[]); // 3.12.1
void printAverage(FILE *reportFile, float total[]); // 3.12.2
int main(void)
{
float total[TOTALS];
FILE * reportFile; // step 1 for a file
reportFile = fopen("./report.lst","wt"); // step 2 for a file
printReportHeadings(reportFile); // 3.1
initializeAccumulators(total); // 3.2
employeeRecord employeeData[1];
bool addEmployee = true;
while(addEmployee)

{
int i = 0;
inputEmployeeData(employeeData[i]); // 3.3
employeeData[i].gross = calculateGross(employeeData[i]); // 3.4
calculateTaxes(employeeData[i]); // 3.5
calcNetPay(employeeData[i]); // 3.6
calcRegularHours(employeeData[i]); // 3.7
calcOvertimeHours(employeeData[i]); // 3.8
printEmployeeData(reportFile,employeeData[i]); // 3.9
addDetailsToAccumulator(total, employeeData[i]); // 3.10
addEmployee = addEmployeeAnsw(); // 3.11
i++;
}
printSummaryReport(reportFile, total); //3.12
fclose(reportFile); // step 4 for a file
while (getchar() != '\n'); // same as fflush(stdin)
return 0;
}
void printReportHeadings(FILE * reportFile) // 3.1
{
fprintf(reportFile,REPLINEA);
fprintf(reportFile,REPLINEB);
fprintf(reportFile,REPLINEC);
}
void initializeAccumulators(float total[]) //3.2
{
for (int i = 0; i < TOTALS; i++)
{
total[i] = 0;
}
}

void inputEmployeeData(employeeRecord &employee) // 3.3


{
printf(" Enter employee's last name: ");
scanf("%s",employee.lastName);
printf(" Enter employee's first name: ");
scanf("%s",employee.firstName);
printf(" Enter the hours worked: ");
scanf("%f",&employee.hours);
printf(" Enter the hourly pay rate: ");
scanf("%f",&employee.payRate);
printf(" Enter the deferred earnings: ");
scanf("%f",&employee.deferred);
}
float calculateGross(employeeRecord &employee) // 3.4
{
if (employee.hours <= 40)
return employee.hours * employee.payRate;
else
return (40 * employee.payRate) + (1.5*employee.payRate*(employee.hours-40));
}
void calcNetPay(employeeRecord &employee) // 3.6
{
employee.netPay = employee.gross-employee.fedTax-employee.stateTaxemployee.ssiTax-employee.deferred;
}
void calcRegularHours(employeeRecord &employee) // 3.7
{
employee.regularHours = (employee.hours < 40? employee.hours:40);
}

void calcOvertimeHours(employeeRecord &employee) // 3.8


{
employee.overtimeHours = (employee.hours <= 40? 0:employee.hours -40);
}
void printEmployeeData(FILE *reportFile,employeeRecord &employee) // 3.9
{
char fullName[15+2+10+1];
strcpy(fullName, employee.lastName);
strcat(fullName, ", ");
strcat(fullName, employee.firstName);
fprintf(reportFile,REPFORMATA,fullName,employee.payRate,employee.regularHours,
employee.gross,employee.fedTax,employee.ssiTax,employee.netPay);
fprintf(reportFile,REPFORMATB,employee.overtimeHours,employee.stateTax,employee.deferred);
}
void addDetailsToAccumulator(float tot[], employeeRecord &employee) //3.10
{
tot[FEDTAX] += employee.fedTax;
tot[STATETAX] += employee.stateTax;
tot[SSITAX] += employee.ssiTax;
tot[GROSS] += employee.gross;
tot[HOURS] += employee.hours;
tot[PAYRATE] += employee.payRate;
tot[DEFERRED] += employee.deferred;
tot[NETPAY] += employee.netPay;
tot[REGULARHOURS] += employee.regularHours;
tot[OVERTIMEHOURS] += employee.overtimeHours;
tot[EMPLOYEES] += 1;
}

bool addEmployeeAnsw() // 3.11


{
char continueAnsw;
while (getchar() != '\n'); // same as fflush(stdin)
printf("continue (y/n)? ");
scanf("%c", &continueAnsw);
if (continueAnsw == 'n' || continueAnsw == 'N')
return false;
else
return true;
}
void printSummaryReport(FILE * reportFile, float tot[]) // 3.12
{
printTotal(reportFile, tot); // 3.12.1
printAverage(reportFile, tot); // 3.12.2
}
void printTotal(FILE *reportFile, float tot[]) // 3.12.1
{
fprintf(reportFile,REPFORMATC,"Total",tot[PAYRATE],tot[REGULARHOURS],tot[GROSS],tot[FEDTAX],tot[SSITAX],tot[NETPAY]);
fprintf(reportFile,REPFORMATB,tot[OVERTIMEHOURS],tot[STATETAX],tot[DEFERRED]);
}
void printAverage(FILE *reportFile, float tot[]) // 3.12.2
{
fprintf(reportFile,REPFORMATC,"Average",tot[PAYRATE]/tot[EMPLOYEES],tot[REGULARHOURS]/tot[EMPLOYEES],
tot[GROSS]/tot[EMPLOYEES],tot[FEDTAX]/tot[EMPLOYEES],tot[SSITAX]/tot[EMPLOYEES],
tot[NETPAY]/tot[EMPLOYEES]);
fprintf(reportFile,REPFORMATB,tot[OVERTIMEHOURS]/tot[EMPLOYEES],tot[STATETAX]/tot[EMPLOYEES],
tot[DEFERRED]/tot[EMPLOYEES]);
}

========================================== calculateTaxes.cpp ===========================================


/*
Program: calcTaxes (External Function)
Author: Josue Herrera
Date: 06/29/2015
*/
#include "employeeRecord.h"
#define FEDTAXRATE 0.15
#define STATETAXRATE 0.07
#define SSITAXRATE 0.0775
float calcFedTax(float gross,float deferred); // 3.5.1
float calcStateTax(float fedTax); // 3.5.2
float calcSSITax(float gross,float deferred); // 3.5.3
void calculateTaxes(employeeRecord &employee) // 3.5
{
employee.fedTax = calcFedTax(employee.gross,employee.deferred); // 3.5.1
employee.stateTax = calcStateTax(employee.fedTax); // 3.5.2
employee.ssiTax = calcSSITax(employee.gross,employee.deferred); // 3.5.3
}
float calcFedTax(float gross,float deferred) // 3.5.1
{
return (gross-deferred)*FEDTAXRATE;
}
float calcStateTax(float fedTax) // 3.5.2
{
return fedTax * STATETAXRATE;
}
float calcSSITax(float gross,float deferred) // 3.5.3
{
return (gross-deferred)*SSITAXRATE;
}

=========================================== employeeRecord.h =============================================


typedef char STR15[15+1];
typedef char STR10[10+1];
typedef struct employeeRecord
{
STR15 lastName;
STR10 firstName;
float hours,
payRate,
deferred,
gross,
fedTax,
stateTax,
ssiTax,
netPay,
regularHours,
overtimeHours;
} employeeRecord;

d and f) Program report and unix proof

e) ======================================== makefile ====================================================


all:
run.exe calculateTaxes.o
run.exe:

main2.cpp calculateTaxes.o
g++ main2.cpp calculateTaxes.o o run.exe

calculateTaxes.o:

calculateTaxes.cpp
g++ -c calculateTaxes.cpp o calculateTaxes.o

Вам также может понравиться