Sie sind auf Seite 1von 3

Homework Description:

Revise homework 2 to use object oriented programming.

Write code in python to read payroll data of hourly workers from a file, store the data into a list of object
(see course notes of student roster as an example) and print pay information to both the console and an
output file.

A sample of data found in payroll.txt is below: (please create your own data)
4123 Adam Carlson 12 15.0 8.0 1 3
5456 Barney Craig 22 4 11.6 5 12
7189 Catlyn Davis 10 8 7.5 2
2012 David Ellis 9 4.5 1.5 1
1345 Emma Franklin 28 40
1678 Dan George 15 6.5 2.0 3.5 4 5.0
1901 Phil Hall 10 9 8.5 7 6.5 5 1.5
8234 James Henry 17 0 0 0 1 0 0 4
2567 Lisa Lincoln 55 5.0 3.0 2.5 3
3890 Mike Watson 21 12.5 16.5 11

Each row represent the pay information of one employee.

The data is organized as columns consisting of the following information about each
employee: Employee ID, Employee First Name, Employee Last Name, hourly wage, a list
of daily hours worked by the employee.

For example, the first row: 4123 Adam Carlson 12 15.0 8.0 1 3
This row has the following entries:

Employee ID: 4123

Employee First Name: Adam

Employee Last Name: Carlson

Hourly wage: 12

Daily hours worked: 15.0 8.0 1 3


Which means this employee worked a total of four days: the first day worked 15 hours,
day2 worked 8 hours, day3 worked 1 hour, and day4 worked 3 hours.

One way to read this data from the file is to read it one line at a time. Where each
line represent a single employee information. For example

If the name of your file object is f, you can loop through it one line at a time:

For line in f:

Then you can split the line using the split function.

e.g.,

columns = line.split()

id = columns[0] # "123"
name = columns[1]+' '+columns[2] # "Suzy"
wage = float(columns[3])
days = columns[4:]

Required Features to use:


1. Object oriented programming
2. initializer
3. Files read and write
4. Functions
5. Formatted floating point values
6. Calculate the total pay for each employee and print the output to the screen and send a copy
to the output file: The printed and file output information about each employee consists of
employee id, full name, total hours worked, total pay, average hours worked each day (see
sample file output below)

What to submit:

Create a word document named your Full Name + hw3, if student name is Lisa Lincoln, the document
name should be LisaLincolnHw1.docx

Type your name inside the word document

Copy and paste your own code and a screen capture of sample I/O for each exercise.

Submit the word document to blackboard by due date.

The order of columns in the input files:


columns = line.split()
id = columns[0] # "123"
name = columns[1]+' '+columns[2] # "Suzy"
wage = float(columns[3])
days = columns[4:] #

Sample input file payroll.txt

Sample Output to console (similar output is also sent to file)


Adam Carlson ID 4123 worked 27.0hourly pay $12.0 hours: 6.75 / dayTotal Pay: $324.00
Barney Craig ID 5456 worked 32.6hourly pay $22.0 hours: 8.15 / dayTotal Pay: $717.20
Catlyn Davis ID 7189 worked 17.5hourly pay $10.0 hours: 5.83 / dayTotal Pay: $175.00
David Ellis ID 2012 worked 7.0hourly pay $9.0 hours: 2.33 / dayTotal Pay: $63.00
Emma Franklin ID 1345 worked 40.0hourly pay $28.0 hours: 40.00 / dayTotal Pay:
$1120.00
Dan George ID 1678 worked 21.0hourly pay $15.0 hours: 4.20 / dayTotal Pay: $315.00
Phil Hall ID 1901 worked 37.5hourly pay $10.0 hours: 6.25 / dayTotal Pay: $375.00
James Henry ID 8234 worked 5.0hourly pay $17.0 hours: 0.71 / dayTotal Pay: $85.00
Lisa Lincoln ID 2567 worked 13.5hourly pay $55.0 hours: 3.38 / dayTotal Pay: $742.50
Mike Watson ID 3890 worked 40.0hourly pay $21.0 hours: 13.33 / dayTotal Pay: $840.00

Das könnte Ihnen auch gefallen