Google Answers Logo
View Question
 
Q: PROGRAMMING HELP ( No Answer,   0 Comments )
Question  
Subject: PROGRAMMING HELP
Category: Computers > Programming
Asked by: unc0ntr0l-ga
List Price: $8.00
Posted: 09 Apr 2006 17:16 PDT
Expires: 09 Apr 2006 18:00 PDT
Question ID: 717222
Ok i need to solve this program! And I have provided what I have done
so far but im lacking the arrays and some other stuff! help would be
greatly appreciated!

Spring 2006 Introduction to C - Program 5
Automated Payroll
Assigned: 3/27/06
Due Date: 4/10/06, 3 am WebCT Time
Objectives
1. To give students practice in using arrays.
2. To give students practice reading from files and writing to files.

The Problem: Automated Payroll
Many companies have a system where employees clock in and clock out to
determine how much time they work each week. Since these records are
already automatically stored in files on companies' computers, it only
makes sense to use these files to help calculate how much each
employee should get paid. In order to determine how much an employee
gets paid each week, you need to know the following two pieces of
information:

1) The number of hours they worked in a week
2) Their hourly pay rate

If an employee works 40 or less hours a week, then they simply get
paid the number of hours they worked times their hourly pay rate. If
an employee works more than 40 hours, then they get paid an extra 50%
of their regular pay for the hours over 40 they worked. (For example,
if an employee's pay rate is $10/hour and the employee works 50 hours,
then he/she would get paid $550, because he/she gets $10x50 = 500
normally, plus an extra .5x(10 hr)x($10/hr) = $50 for his/her
overtime.

You are to write a program that reads in the raw time data from the
file "clock.txt", processes the payroll and outputs the final results
to the file "payroll.txt". The input file will consist of all employee
data for 10 weeks. Your output file will have summaries for each week
as well as overall summaries for each employee. You are guaranteed
that the file will contain data for no more than 20 employees.

Format of clock.txt
The first line of the file will contain a single positive integer, n,
in between 1 and 20, inclusive, which represents the number of
employees at the company. These employees will be numbered 0 through n
? 1. The next n lines of the file will each contain a single positive
real number representing the hourly pay rate for the corresponding
employee. (Namely, the first line in this set contains the pay rate
for employee 0, the second line contains the pay rate for employee 1,
etc.) The rest of the file will contain 10 sets of data. Each set of
data represents the data for that particular week. The first line of
each set of data will contain a single positive integer k,
representing the number of employee records for the week. (Note: a
single employee record denotes one instance of an employee clocking in
and clocking out.) The following k lines will contain one employee
record each. Each employee record will have the following format:

Emp# HrIn MinIn HrOut MinOut

All five of these values will be integers. The first integer, Emp#,
represents the employee number and will always be in between 0 and n ?
1, inclusive. The second integer, HrIn, represents the hours (in
military time) that the given employee clocked in to work. This value
is guaranteed to be in between 0 and 23, inclusive. The third integer,
MinIn, represents the minutes (in military time) that the given
employee clocked in to work. This value is guaranteed to be in between
0 and 59, inclusive. The last two values, HrOut and MinOut, represent
the hours and minutes respectively (in military time), that the given
employee clocked out of work. You are guaranteed that this second time
occurs later in the day than the first. (Thus, no employee EVER works
through midnight.) Thus, the following line:

3 8 0 16 30

means that employee number 3 worked from 8am to 4:30pm, for a total of 8.5 hours.

Format of payroll.txt
The first line of the output file will contain the following

Number of employees: n

where n is the number of employees in the company. The second line
will be blank. Following that will be ten sets of data, one for each
of the ten weeks in the input file. Each corresponding output data set
will contain exactly n+2 lines. The first two lines will be as
follows:

Week #
EmpID    Hours   Pay

Substitute the corresponding week (1 through 10) for #, and separate
each heading on the second line with a tab. In the following n lines,
list the appropriate data for employees 0 through n-1, in order,
separated by tabs. The second value will be the total number of hours
they worked in the week, printed to two decimal places, and the last
value will be their pay for the week, printed to two decimal places.

Following the ten sets of data, after a blank line, list the totals
for each employee. The first two lines for this last set of data
should be as follows:

Total
EmpID    Hours   Pay

Then, list the corresponding information in the same format as the
data sets for each individual week for the ten week period.

 
Example Input and Output Files
These will be posted on both WebCT and the course webpage as individual text files.

References
Textbook: Sectionss 9.1-9.6, 13.4-13.6			
Notes: Arrays and Files

Grading Notes
In order to receive full credit, not only does your program have to
work properly, but you must do the following:

1) Use multiple functions (at least one function other than main)
2) Define constants for appropriate values (you need to figure out what these are)

Restrictions
Name the file you create and turn in payroll.c. Although you may use
other compilers, your program must compile and run using gcc or
jGRASP. Your program should include a header comment with the
following information: your name, course number, section number,
assignment title, and date. You should also include comments
throughout your code, when appropriate. If you have any questions
about this, please see a TA.

Input Specification
Assume that the input file that we use for testing adheres to all the
specifications described above. (In essence, you do not have to error
check the input file at all.)

Output Specification
Your output file should follow the format described above. 

Deliverables
A single source file named payroll.c turned in through WebCT.



what I have:

#include <stdio.h>
#include <stdlib.h>


/* declare functions */

/* Get the employee data */
void get_employee_data(FILE* fp,int* id, float* rate, float* hours);

/* Calculate gross pay */
float calc_gross_pay(float rate, float hours);


/* Calculate net pay */
float calc_net_pay(float gross_pay);


/* Display results */
void display(FILE* fp,int id, float net_pay);


int main()
{
int id, hrin, minin, hoout, minout; /* employee identification */
float rate; /* hourly wage */
float hours; /* hours worked */
float gross_pay; /* gross pay */
float net_pay; /* net pay */
float total_payroll=0; /* total payroll */
float average_payroll=0; /* total payroll */
int nums=0; /* number employees */

FILE *fpin; /* read file pointer */
FILE *fpout; /* write file pointer */

fpin = fopen("clock.txt","r"); /* open file for reading */

/* check if file open */
if(fpin == NULL)
{
printf("file 'clock.txt'  cannot be opened for reading\n");
exit(1); /* close all file streams  and terminate */
}

fpout = fopen("employees.out","w"); /* open file for writing */

/* check if file open */
if(fpout == NULL)
{
printf("file 'employees.out'  cannot be opened for writing\n");
exit(1); /* close all file streams  and terminate */
}

/* read employees in loop */

/* Get the employee data */
get_employee_data(fpin,&id, &rate, &hours);

while(!feof(fpin))
{
nums++; /* count employees */

/* Calculate gross pay */
gross_pay = calc_gross_pay(rate, hours);


/* Calculate net pay */
net_pay = calc_net_pay(gross_pay);

/* sum totals */
total_payroll = total_payroll + net_pay;

/* Display results */
display(fpout,id,  net_pay);

/* get next employee data */
get_employee_data(fpin,&id, &rate, &hours);

}

/* close read file */
fclose(fpin);



/* caculate average payents */
average_payroll = total_payroll / nums;

/* print total */
fprintf(fpout,"\nTotal Payroll: %.2f  Average
Payroll:%.2f\n",total_payroll, average_payroll);
printf("\nTotal Payroll: %.2f  Average Payroll:
%.2f\n",total_payroll,average_payroll);

/* close write file */
fclose(fpout);

return 0;
}




/* Get the employee data */
void get_employee_data(FILE* fp,int* id, float* rate, float* hours)
{

/* get employee id */
fscanf(fp,"%d",id);

/* get employee id */
fscanf(fp,"%f",rate);

/* get employee id */
fscanf(fp,"%f",hours);

}


/* Calculate gross pay */
float calc_gross_pay(float rate, float hours)
{
float gross_pay = 0;

if(hours <= 40)
    gross_pay = rate * hours;
else
    gross_pay = rate * 40 + (hours - 40) * rate * 1.5f;

return gross_pay;
}



/* Calculate net pay */
float calc_net_pay(float gross_pay)
{

float tax = .23625f * gross_pay;

float net_pay = gross_pay - tax;

return net_pay;
}



/* Display results */
void display(FILE* fp, int id, float net_pay)
{

fprintf(fp,"%d %.2f\n",id,net_pay);
printf("%d %.2f\n",id,net_pay);

}
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy