Subject: Payroll program maintenance. Clearly state the grading option you have
ID: 3676858 • Letter: S
Question
Subject: Payroll program maintenance. Clearly state the grading option you have completed on a cover sheet with your name and the date the project is submitted for grading. Please use a large envelop with you name in the upper right hand corner.
We have an immediate need to migrate the existing payroll application from Microsoft “C” to standard GNU/Linux “C” using the “gcc” translator. Please complete this program ASAP (PDQ) or update your resume. You will be given a chance to travel and meet new people at your own expense.
Our contract with the customer specifies top-down-iterative-refinement for the design and implementation. The structure specified in the following design must be preserved or you will be terminated. Jackson’s Technique and Object Oriented Design (OOD) produce arguably cleaner solutions but you may not use them. All input must be from a text file and the report printed to a text file. Please prompt the user for the names of the input and report files at run time. Management would be really impressed if the user had a choice between specifying the names of the input and report files at the command line with your software prompting for the names if they are not specified. Highlight this code if implemented.
Sample data follows. Please process the data in L2CS2347CtlDataSp16.dat as soon as the software is operational.
Emp. No.
Given
Surname
Department
YTD
Pay Rate
Hours
12
Brooke
Tyler
Acct
110100.00
13.24
40.0
6
Kavanaugh
Sarah
Acct
66600.00
17.87
64.5
10
Fruci
Jordan
Acct
36600.00
10.00
10.0
22
Horn
John
Acct
109999.56
41.3
36.7
24
Pike
Jeremy
Acct
1358.34
16.22
53.5
13
Silva
Julian
DP
110090.00
10.00
1.0
5
Oliver
Logan
Mgt
673478.34
187.56
40.0
3
Nienburg
Dylan
Mgt
134234.34
67.42
56.2
1
Zhang
Zhache
Sales
11345.22
23.77
67.3
4
Curtis
Harrison
Sales
234.56
17.56
38.9
15
Welch
Wade
Sales
2342.34
27.86
45.6
17
Moreno
Issac
Sales
67000.00
34.23
40.0
The body of the report should consist of 4 detail lines per page exclusive of headings, department control breaks, and page control break information. Management would be impressed if dollar amounts contain commas in appropriate locations. Hint:
Report Format
Report
Header
Page
ACME Sports Inc.
“We are the best, you use the best!”
ACME
Emp# Name Dept. New YTD Gross FICA Net
12 Tyler Brooke Acct ?????.?? ????.?? ????.?? ???.??
6 Sarah Kavanaugh Acct ?????.?? ????.?? ????.?? ???.??
10 Jordan Fruci Acct ?????.?? ????.?? ????.?? ???.??
22 John Horn Acct ?????.?? ????.?? ????.?? ???.??
Page Totals: $xxxx.xx $xxxx.xx $xxx.xx
Page 1
Report
Body
ACME
Emp# Name Dept. New YTD Gross FICA Net
24 Jeremy Pike Acct ?????.?? ????.?? ????.?? ???.??
Department Totals: ttttttt.tt tttttttt.tt tttttt.tt
13 Julian Silva DP ?????.?? ???.?? ????.?? ???.??
Department Totals: ttttttt.tt tttttttt.tt tttttt.tt
5 Logan Oliver Mgt ?????.?? ????.?? ????.?? ???.??
3 Dylan Nienburg Mgt ?????.?? ????.?? ????.?? ???.??
Department Totals: ttttttt.tt tttttttt.tt tttttt.tt
Page Totals: $xxxx.xx $xxxx.xx $xxx.xx
Page 2
Additional pages in the body of the report with 4 detail lines per page with the possible exception of the last page.
Report
Trailor
-
You may add information
Report Summary
Records processed: 785
Total Gross: $yyy,yyy.yy
Total Net: $ yy,yyy.yy
Total FICA: $ yyy.yy
Page 200
Calculate the gross pay as the product of the number of hours worked and pay rate. Our policy is to pay time-and-a-half for all work in excess of 40 hours.
Our accounting department has supplied the following logic for computing FICA tax. The FICA Limit is currently $110,10000 and the FICA Rate is 7.1%.
no
yes
Ytd >= 110,100
Pay no tax
yes
no
Ytd + gross <= 110,100
Pay tax on total gross
Pay tax only on (100,100 – ytd)
In a properly drawn flow chart, all questions (contain a relational or logical operator) should be in diamonds. The light magenta text in rectangles has been substituted above for diamonds by the accounting department.
Please, we must anticipate yearly changes to the FICA Rate and FICA Limit. We desire to minimize the amount of time require from program maintenance when change occurs. At the same time we do not wish to incur the overhead or risk of asking the operator to input these values every time the program is executed. Management would prefer the values for the FICA Rate and FICA Limit to be read from a text file when the system starts.
The solution that must be migrated to the new platform (less department control breaks) follows.
Page Control Break Solution
Using Top-Down-Iterative-Refinement
Assume we do not know the number of records in the input. Each page is to contain appropriate column headings and exactly 20 detail lines per page (use 4 lines per page to test the lab) with the possible exception of the last page. The report should contain a cover page with the company name and logo. A trailer page should summarize the contents of the report. Be sure not to print page headings on a page that does not contain any detail lines. The following FICA calculations are for the purpose of demonstrating the output format, they are not accurate.
Report Format
Raw Data (sample)
Report
Header
ACME Sports Inc.
“We are the best, you use the best!”
Name Pay Rate Hrs
Adam 2.20 10.0
Bart 3.00 10.0
Betty 4.50 20.0
···
ACME
Name Gross FICA Net
Adam 22.00 1.50 $20.50
Bart 30.00 2.00 $28.00
Betty 90.00 4.50 $95.50
···
Page Totals: $485.76 $75.00 $410.76
Page 1
Report
Body
ACME
Name Gross FICA Net
Tom 20.00 2.50 $17.50
Sam 30.00 2.00 $28.00
Sara 40.00 4.50 $35.50
···
Page Totals: $500.76 $50.00 $450.00
Page 2
Additional pages in the body of the report with 20 detail lines per page with the possible exception of the last page.
Report
Trailer
Report Summary
Records processed: 785
Total gross: $4,896.72
Total FICA: $ 896.72
Total Net: $4,000.00
Page 200
Main Line Control or Driver
Generate Report
1) Perform Initialization.
2) Perform Calculate Payroll
Until EOF = “Yes”.
3) Perform Closing.
4) Stop Run.
Initialization
Calculate Payroll
Closing
1) Open (2) Files.
2) Print Cover Page
3) Print Heading 1st page
4) PK = 1 and LK = 0.
5) MaxLines = 20.
6) Set page & report totals
to 0 including:
Pgross, Pfica,Pnet,
Rgross, Rfica, Rnet
7) EOF = “No”.
8) Read RawData
At End set EOF = “Yes”.
1) If LK = MaxLines
Perform New Page.
2) Perform Calculate Gross.
3) Perform Calculate FICA
4) Write Detail Line.
5) LK++, compute page totals
6) Read RawData
At End set EOF = “Yes”.
1) Write totals last page.
2) PK++
3) Write summary heading.
4) Add last page totals to report totals.
4) Write summary.
5) Write page number.
6) Close files.
New Page
Calculate Gross
Calculate FICA
Finish Last Page.
1) Write page summaries.
2) Write page number.
3) Add page totals to report
totals
Start Next Page.
4) PK++
5) Write page headings.
6) LK = 0.
Set page totals to zero.
Calculate gross pay. Pay regular time for <= 40 hours, time and a half for hours over 40, and double time for time during company recognized holidays.
Calculate FICA using current government regulations.
Legend:
PK: Page counter.
LK: Line counter (lines printed on page).
MaxLines: Desired detail lines per page.
EOF: Flag used to indicate end of file.
“D” Option (best grade is 65):
Convert the Microsoft version of the application in the class notes to GNU/Linux standard “C” with page breaks and department control breaks. You must use fscanf and fprintf. All I/O for employee records must be to files. Compile the application using gcc. You must submit a copy of all source files, data files, and the results (report).
“C” Option (best grade is a 79):
You need not complete the “D” option. Solve the problem using gcc but the modules “New Page,” Calculate Gross,” and “Calculate FICA” must be implemented as subprograms. You may not use any global variables. “Calculate Gross” and “Calculate FICA” must return their values through the name of the function. All parameters to “Calculate Gross” and “Calculate FICA” should be passed by value. “New Page” must pass any results back through the parameter list (CBR). A script must be used to produce (compile and link) the executable. You must use the following directory structure.
src directory
Project Directory
Driver
Script
Executable
Data file
Report
Calculate Gross
Calculate FICA
New Page
You must submit a copy of all source files, data files, the results (report), and the script used to build the “C” option executable.
“B” Option (best grade is 89);
Implement the “C” option but build the application using the “make” utility. You must submit a copy of all source files, data files, the results (report), the script used to build the “C” option executable, and the “Makefile” to produce the “B” option executable.
“A” Option (best grade is 100);
Grades in excess of 89 will be based on proper use of naming conventions, indentation, documentation, program clarity, and other software system attributes.
Hint: , , , , - carriage control for newline, tab, backspace, carriage return, and form feed. There are more. Look them up. Hint: left justify in field of 10 printf(“%-10d”,59), to force sign printf(“%+10d”,59), %-+d would force both the sign to print and left justify, %5.2f implies print with two digits to the right of the decimal point with a maximum of 5 digits to the left, %0 and %x prints an integer in octal and hexadecimal respectively. #define TopOfPage ‘’ and #define Bell ‘’ may be used to skip to the top of a page or ring the bell respectively
Emp. No.
Given
Surname
Department
YTD
Pay Rate
Hours
12
Brooke
Tyler
Acct
110100.00
13.24
40.0
6
Kavanaugh
Sarah
Acct
66600.00
17.87
64.5
10
Fruci
Jordan
Acct
36600.00
10.00
10.0
22
Horn
John
Acct
109999.56
41.3
36.7
24
Pike
Jeremy
Acct
1358.34
16.22
53.5
13
Silva
Julian
DP
110090.00
10.00
1.0
5
Oliver
Logan
Mgt
673478.34
187.56
40.0
3
Nienburg
Dylan
Mgt
134234.34
67.42
56.2
1
Zhang
Zhache
Sales
11345.22
23.77
67.3
4
Curtis
Harrison
Sales
234.56
17.56
38.9
15
Welch
Wade
Sales
2342.34
27.86
45.6
17
Moreno
Issac
Sales
67000.00
34.23
40.0
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
FILE *outFile, *inFile;
float hrs[20],pyRt[20],ficaTax[20], YTD[20], gross[20], net[20],Pgross,Pfica,Pnet, Rgross, Rfica, Rnet;
int empNum[20],pgKt, lnKt, mxLn;
char outputName[21], inputName[21], firstName[20][15], lastName[20][20],dep[20][6],ans ;
//end variable declerations//
//begin input file//
printf(" Enter the name of input file[max 20 characters]: ");
scanf("%s", &inputName);
inFile=fopen(inputName,"r");
if(inFile==NULL)
{
printf("Input file does not exist, program terminating.");
exit(1);
}
//end input file// //begin output file//
printf(" Enter the name of file to hold the results[max 20 characters]: ");
scanf("%s",&outputName);
if((outFile=fopen(outputName,"r"))!=NULL)
{
printf(" %s exists, do you want to overwrite existing file?(y or n): ",outputName);
scanf("%*c%c",&ans);//input resp, skips 1 character in buffer(<cr>)
if((ans=='n')||(ans=='N'))
{
printf(" Program aborted to prevent overwrite!");
exit(1);
}
}
outFile=fopen(outputName,"w");//opens/overwrites file if answer was not 'n'||'N'
if(outFile==NULL)
{
printf(" Could not create file, program aborted!");
exit(1);
}
//end output file//
//begin header page//
fprintf(outFile,"%27s","AMCE Inc.");
fprintf(outFile," %19s", "We are the best, you use the best!");
//end header page//
//Begin Total definitions
pgKt=1; lnKt=0; mxLn=20; Pgross=0; Pfica=0;
Pnet=0; Rgross=0; Rfica=0;
Rnet=0; //End Total definitions
//Begin Read Data
int a=0;//counter for read data loop
while((fscanf(inFile,"%i",&empNum[a]))!=EOF)
{
fscanf(inFile,"%c%c%c%f%f%f%f",&firstName[a],&lastName[a],
&dep[a],&YTD[a],&pyRt[a],&hrs[a]);
a++;
}
//End Read Data
//begin calculate Payroll
int b=a;
a=0;
while(a<=b)
{
if( lnKt=mxLn)
{
newPage(pgKt,lnKt,Pgross,Pfica,Pnet,Rgross,Rfica,Rnet,outFile);
}//new page
calGross(a, pyRt,hrs, gross);
calFica(a,ficaTax,gross,YTD);
fprintf(outFile,"%2i%-10s%-10s%10.2f%10.2f%10.2f%10.2f ",empNum[a],
firstName[a],lastName[a],YTD[a],gross[a],ficaTax[a],net[a]);//end print ln
lnKt++;
Pgross=Pgross+gross[a];
Pfica=Pfica+ficaTax[a];
Pnet=Pnet+net[a];
a++;
}
//end calculate Payroll
}
//end output file//
//begin header page//
fprintf(outFile,"%27s","AMCE Inc.");
fprintf(outFile," %19s", "We are the best, you use the best!");
//end header page//
//Begin Total definitions
pgKt=1;
lnKt=0;
mxLn=20;
Pgross=0;
Pfica=0;
Pnet=0;
Rgross=0;
Rfica=0;
Rnet=0;
//End Total definitions
//Begin Read Data
int a=0;//counter for read data loop
while((fscanf(inFile,"%i",&empNum[a]))!=EOF)
{
fscanf(inFile,"%c%c%c%f%f%f%f",&firstName[a],&lastName[a],
&dep[a],&YTD[a],&pyRt[a],&hrs[a]);
a++;
}
//End Read Data
//begin calculate Payroll
int b=a;
a=0;
while(a<=b)
{
if( lnKt=mxLn)
{
newPage(pgKt,lnKt,Pgross,Pfica,Pnet,Rgross,Rfica,Rnet,outFile);
}//new page
calGross(a, pyRt,hrs, gross);
calFica(a,ficaTax,gross,YTD);
fprintf(outFile,"%2i%-10s%-10s%10.2f%10.2f%10.2f%10.2f ",empNum[a],
firstName[a],lastName[a],YTD[a],gross[a],ficaTax[a],net[a]);//end print ln
lnKt++;
Pgross=Pgross+gross[a];
Pfica=Pfica+ficaTax[a];
Pnet=Pnet+net[a];
a++;
}
//end calculate Payroll
//begin closing
pgKt++;
fprintf(outFile," %24s","Report Summary");
fprintf(outFile," %s%i","Records Processed: ",b);
fprintf(outFile," %s%f"," Total Gross: $",Rgross);
fprintf(outFile," %s%f"," Total Net : $",Rnet);
fprintf(outFile," %s%f"," Total FICA : $",Rfica);
fprintf(outFile,"%s%i","Page ",pgKt);
fclose(inFile);
fclose(outFile);
//end closing
return 0;
}
float newPage(int x,int y,float c,float d ,float e,float f, float g, float h, FILE *filename){
//begin last page
fprintf(filename," %-25s%10.2f%10.2f%10.2f","Page Totals:",c,d,e);
fprintf(filename," %s%i","Page ",x);
f=f+c;
g=g+d;
h=h+e;
//end last page //begin new page
x++;
fprintf(filename," %s%s%s%s%s%s%s","Emp#","Name","Dept.","New YTD","Gross","FICA","Net");
y=0;
c=0;
d=0;
e=0;
//end new page
return x,y,c,d,e,f,g,h;
}
//begin ficaCalc function
float ficaCalc(int p,float m[],float n[],float o[]){//fica calculations function
float ficaLimit=(102,000);
float ficaRate=(6.2);
float v1= (o[p] + n[p]);//sets v1 to the sum of YTD & gross for an easily checkable value
if (v1 <= ficaLimit){m[p] = (n[p] * ficaRate);}
else if((v1>ficaLimit)&&(o[p]<ficaLimit)){m[p] = ((ficaLimit - o[p])*ficaRate);}
else if (o[p] > ficaLimit){m[p] = 0;}
v1=0;
return m[p];}
//end ficaCalc function
float grossCalc(int k,float i[], float j[], float l[]){
if(j[k]<=40){
l[k]=i[k]*j[k];}//pay normal rate
else if (j[k]>40){
i[k]=(i[k]*1.5);//change payrate for overtime
l[k]=i[k]*j[k];}
return l[k];//return gross
}