COP 3223 Introduction to C Assignment 9.RAR

COP 3223 Introduction to C Assignment 9


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 next line will contain an integer w indicating how many
weeks of data will follow. The rest of
the file will contain w 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

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

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

Number of employees: n

where n is the
number of employees in the company. The second line will be a printout of the
number of weeks of data in the format:

Number of weeks: w

The third line will be blank. Following that will be w
sets of data, one for each of the w 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 w 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 w week period.

Example Input and Output Files

Sample clock.txt






10 30 13

0 7
0 16 30


9 0 14

7 0 23 0

1 9 0 22 0

1 7 20 23 20


10 0 15 0

8 0 12 0

0 9 30 11 30

Sample Output – payroll.txt

Number of employees: 2
Number of weeks: 3


EmpID Hours

9.50 52.25

3.00 30.00


EmpID Hours

14.50 79.75

42.00 410.00


EmpID Hours

4.00 22.00

2.00 20.00


EmpID Hours

28.00 154.00

47.00 460.00

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 2 functions other than main)

2) Define
constants for appropriate values (you need to figure out what these are)

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


Your assignment should be
submitted via Webcourses by the deadline. No assignments will be accepted via
email. Your submission should include a
single .c file called payroll.c
. Remember that your program will be
graded using DevC++ , so be sure that
your submitted code runs correctly in this IDE.
If you do not have DevC++ on your personal machine, you may use a
computer in any lab to test your code.
Powered by