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:

                              For Salary, the monthly pay is one-twelfth (1/12) of the pay_amount.

                              For Hourly, the monthly pay is 40 times the pay_amount.

For Special, the pay is the pay_amount if a date was given or the pay is pay_amount times 4 if no date is given

The program should print the paycheck total to the screen.  In VERIFY mode, a message giving employee name and paycheck amount should be printed to the output file.

 

Task 2) If a new employee has been hired, the user needs to be able to enter all the data for the new employee and have that employee added to the list.  In VERIFY mode, after the new employee struct has been created, print all of its data to the screen and print a message to the output file stating that a new employee has been added.

 

Task 3) If an employee has left, the user needs to be able to remove an employee with a specific employee number.  If there is no employee in the list with that number, the program should send a message to the user.  In VERIFY mode, a message about the deletion should be printed in the output file.

 

Task 4) The program must let the user update records for name changes like marriage, address changes, changes in pay or type of employ.  In VERIFY mode, a message should be printed to the output file stating that the record for employee_number has been changed.  You do not have to print the changed information.

 

Task 5) The user can request to resort the list by last name.  If the user asks for this, the program should print the newly sorted list into the output file and to the screen.

 

Task 6) The user can request to see just employees of a certain pay type.  If the user requests this, the program should print those employees to the screen.

 

Task 7) If the user has completed all the desired tasks they will choose to end the program.  When this choice is made, the program should print the entire current employee list to a second separate output file using the same format as the input file and then end.  (This file can then be used as an input file for the employees.)

 

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.  

 

Format of input values for use in testing:

 

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:

 

Tilepot, Maxwell Q.

87658765

Salary

38000.00

123 Sesame St. 456

Anytown, MO  33221

Monster, Cookie

12345678

Hourly

1.25

123 Sesame St. 789

Anytown, MO  33221

Teeth, Doctor

44444444

Special 01012001

42.00

34 Tour Bus Rd.

Fountain Blue, NY  56743

Rubble, Barney

98672366

Salary

100000.00

6 Gravel Ave.

Bedrock, AZ  00001

Tron, Bridge

01010101

Special

101.00

10 Alpha Way

Wun, OH  10101