Lab Assignment # 4, CSE
1320-501, Fall 2003
Topic objectives: Linked lists
Structures
Pointers
Strings
Conditional compilation
Due date: December
9, 2003 5:30 pm (absolute deadline)
Early
submission by December 2, 2003 5:30 pm worth eight (8) points extra credit
Your friend Chris Green has been very pleased with all your programs. In fact, with all the help from your software, Chris is now able to hire more staff for the Green Shop. Chris wants you to write a program that will keep track of employees, payroll, and other tasks. Since the shop may be expanding to a second (or third!) location in the future, Chris isn’t sure how many employees there will be in the system and wants your program to be able to accept any number of employees based on the data in an employee info file.
Therefore, your program will create a doubly linked list of employee structures and then perform various functions on the employees in the list. To create the list, your program will read employee data from a file. The data for each employee will be the following items, each employees data will take six lines in the file:
Employee_last_name, first_name I. /* I is for middle initial - Middle initial is optional */
Employee_number /* 8 digit integer */
Pay_type /* One word “Hourly”, “Salary” or “Special” The word */ /* “Special” may be followed by a date as DDMMYYYY */
Pay_amount /* a floating point number representing money */
Street_num Street_name Apt_num /* an integer, a group of words, an optional integer */
City, State_abbrev Zip /* a group of words, a comma, 2-char state, 5-digit zip */
Your program must create a struct type for an employee that can hold all the data described above for a single employee. You must have separate first and last names in the struct, an enumerated type member for the Pay_type data, a union type member for the Pay_amount data (see descriptions below to explain the use of Pay_type and Pay_amount), and members to hold all the other possible employee data.
All the data should be read in from the file in a loop. No line in the file will be blank. Your program should read in employees until the file is empty. For each employee, your program should read the data, store it in a struct and sort the struct into a linked list of employees sorted by employee_number. As each employee is read in, the data that is stored in the struct should also be printed to the screen.
Once all the employees are read in and sorted into the list, print all the data from the sorted linked list into an output file in the list order. You can print it in the same format as the input file or you can print more data on a line.
After the sorted data has been printed to the output file, your program should allow the user to make calculations using the list and make modifications to the list. In the normal program mode, the tasks will just do as described below. In VERIFY program mode (where VERIFY is a flag created using a #define statement), additional output should be logged as noted in the task descriptions below. The user should be able to:
1) Calculate a monthly paycheck for an employee.
2) Add a new employee.
3) Remove an employee who no longer works for the Green Shop
4) Edit an employee’s data (names, numbers, addresses, pay, etc.)
5) Sort the list based on employee last name (and on first name, if last names are the same)
6) Print all employees of a particular Pay_type (ex: all employees who are “Hourly”)
7) Exit the program
Task 1) Calculating a monthly paycheck for an employee depends on the employee’s pay_type and pay_amount as follows:
Implementation requirements:
The program must define and/or use the following data structures:
A struct to hold the data for one employee
A doubly linked list of employees
A #define constant named VERIFY to control conditional compilation
An input file
Two output files
The program must use the following control structures:
A loop to read the lines of input from the file and store them in the structs and create the sorted doubly linked list
A selection control structure and a loop to allow the user to perform any of the tasks in any order
Preprocessor commands to create conditional compilation
The program should perform the following actions in the given order:
Declare and initialize the variables and data structures
In a loop (until the end of file is seen)
Read in the data from the file
Allocate space for a struct and store data in the struct
Link the struct into the sorted doubly linked list
With a selection structure and a loop
Choose a task
Perform task and print output as appropriate
After each task, let the user choose another task until the user chooses the task to end the program.
As in the previous labs, the program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple program files are used, each file should contain a similar header.
Each programmer-defined
function, i.e. each function you write, should have a function header similar
to those used in the examples in the textbook.
This header should include at least the function name, the purpose of
the function, and its inputs and outputs.
This program must be run using the sample data file that will be given. For testing run your program with the values below your own sample data as well. The sample data set that you create must meet the guidelines given in the problem definition.
The program output must be recorded in a script file from OMEGA using the gcc compiler. If you do not know how to create a script file, it is your responsibility to read the instructions on my website and to ask the TA or OIT how to use this function.
Employee_last_name, first_name
I. /* I is for middle initial -
Middle initial is optional */
Employee_number /* 8
digit integer */
Pay_type /*
One word “Hourly”, “Salary” or “Special”
The word */ /* “Special” may be followed by a date as DDMMYYYY */
Pay_amount /*
a floating point number representing money */
Street_num Street_name Apt_num /* an integer, a group of words, an
optional integer */
City, State_abbrev Zip /* a group of
words, a comma, 2-char state, 5-digit zip */
Sample input values for use in testing: