COSC 1306
Spring 2021
Assignment 10: File Input and Output
[1] Objectives: This assignment’s primary purpose is to practice reading from a text file and writing to a
text file. We will use several string functions in the process. There are more than one ways to read from
and write to a file. You will have the freedom to choose ways to read and write. We will assume there
are no e
ors in the file format as specified below to simplify the tasks.
[2] Description: You are implementing a simple payroll system. We have the primary employee data
stored in a file (id, last and first names, pay rate) stored in a comma-separated values (CSV) format. The
ID is unique. We also have a log of sign-in and sign-out of each employee (timestamp and id separated by
two spaces). Assume the first timestamp if for sign in, and the second one with the same id is for sign out.
They always come in a pair in the second file. The timestamp is in the format of hh:mm:ss where hh is
from 0 to23 (military time) and ss should be ignored for this assignment. You have to read from these
two files, calculate the amount of pay each day (not very realistic). Finally, write the pay log to a file. See
the sample program for the format of these files.
Here is what you need to do.
ď‚· Build a table of employees (prog-10-emp.txt), and you can decide whatever format to store the
data, print the table
ď‚· Build a table of sign-in/out log (prog-10-clock.txt), print the table
ď‚· Calculate the amount of pay for each employee,
ď‚· Write a pay log to a text file (prog-10-pay.txt) and to the screen.
The program is longer than the last one because you have to open/close three files. One can do a lot by
calling li
ary functions to do the work in Python. The code that I tested is less than 60 lines.
[3] Requirements: For the past few assignments, I have given you specific guidelines on what functions
to write. You will have to decide that in this assignment.
[4] Input and Output: See sample outputs below and the demo in class.
[5] Deadline: Midnight, Monday, April 26, 2021 (?). The due date may depend on when we are done
with the chapter on Files.
Prog-10-emp.txt
1077,Huang,Stephen,10.00
1002,Smith,John Jr.,20.00
1003,Doe,Jane,42.60
1004,Carter,James,19.50
1005,Johnson,Olin,21.00
1099,Shah,Shishir,30.00
Prog-10-clock.txt
07:59: XXXXXXXXXX
08:00: XXXXXXXXXX
08:01: XXXXXXXXXX
08:01: XXXXXXXXXX
08:10: XXXXXXXXXX
10:01: XXXXXXXXXX
15:59: XXXXXXXXXX
16:11: XXXXXXXXXX
16:21: XXXXXXXXXX
16:30: XXXXXXXXXX
17:01: XXXXXXXXXX
17:10: XXXXXXXXXX
Id Last Name First Name Pay Rate
1077 Huang XXXXXXXXXXStephen XXXXXXXXXX
1002 Smith XXXXXXXXXXJohn Jr XXXXXXXXXX
1003 Doe XXXXXXXXXXJane XXXXXXXXXX
1004 Carter James XXXXXXXXXX
1005 Johnson Olin XXXXXXXXXX
1099 Shah XXXXXXXXXXShishir XXXXXXXXXX
Timestamp Id
08:01: XXXXXXXXXX
17:01: XXXXXXXXXX
08:00: XXXXXXXXXX
16:11: XXXXXXXXXX
08:01: XXXXXXXXXX
16:21: XXXXXXXXXX
08:10: XXXXXXXXXX
17:10: XXXXXXXXXX
07:59: XXXXXXXXXX
15:59: XXXXXXXXXX
10:01: XXXXXXXXXX
16:30: XXXXXXXXXX
ID Hours Amount
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
Prog-10-pay.txt
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX
XXXXXXXXXX