CS115 INTRODUCTION TO COMPUTER PROGRAMMING Programming project #5 Functions, Files, and Lists INTRODUCTION The goal of this programming assignment is to enable the student to practice programming: •...

1 answer below »
emailed assignment 4


CS115 INTRODUCTION TO COMPUTER PROGRAMMING Programming project #5 Functions, Files, and Lists INTRODUCTION The goal of this programming assignment is to enable the student to practice programming: • Reading and writing to files, • Using functions with parameters and returning values • Using lists. PROBLEM DEFINITION: Write a Python program that has either one or two multi-dimensional list or four separate parallel lists for each type of information to store employee information. A program will not be graded if: • It does not pass the needed data to the functions: inputData, computePay, and displayPay. • It does not read and write the employee data to file. The program will have four functions that do the following: main() function The main() function first reads into a list a file of employee data (one employee / per line) with each line consisting of: • name, • hours, • pay rate for each employee The file may not exist the first time, it may exist and be empty, or it may exist and have data. Close the file after reading the information into lists. You may use the split string function to break a line into name, hours, pay rate. The program then enters a loop that ends when 4 is selected by a user and that processes a menu of the following items: 1. Input employees’ information 2. Compute pay for all employees 3. Display payroll report 4. Exit When the user enters: 1. The inputData() function is called. 2. The computePay() function is called. 3. The displayPay() function is called. 4. The program should write the list(s) data to the file by overwriting, and display a message: “Thank you for using our payroll application”. inputData() function The inputData() function is passed the data it uses as parameters when it is called and returning the inputted data. It has a loop, inside the loop are statements to input: • employee name • hours worked • pay rate for one employee and save them in the list(s). The loop repeats to read multiple employee information until a user indicates they no longer wish to enter data. Error checking is required to check the data to insure it does not corrupt the list(s). computePay() function The computePay() function is passed the data it uses as parameters when it is called and returning the calculated data. It calculates the gross amount to be paid to each employee and save the amount in the list based on the formula: a) For the first 40 hours, the rate is the given rate; b) For hours over 40, the rate is 1.5 times the given rate displayPay() function The displayPay() function is passed the data it uses as parameters when it is called. It loops through the two dimensional list (or parallel lists) to display a table in the following format: DOODAD MANUFACTURING COMPANY JUNE PAYROLL EMPLOYEE NAME HOURS WORKED PAY RATE GROSS PAY ------------------- ------------- -------- ------------ Lily Thomas xxx xxx.xx x,xxx,xxx.xx John Doe xxx xxx.xx x,xxx,xxx.xx LaQuanda Shaka xxx xxx.xx x,xxx,xxx.xx Tim Jenkinson xxx xxx.xx x,xxx,xxx.xx USER STORY – Read me 1. I run the program for the 1st time. There is no file to read, the program displays its menu. 2. I select the Display payroll report. As there are no employee's data only the headers are displayed. 3. I select the Compute payroll. As there are no employee’s data nothing happens. 4. I select Input employee information. I enter Tom & Sue’s information. Tom’s rate is 25.75 and hour and he works 42.5 hours a week. 5. I select the Display payroll report. Tom & Sue’s information is displayed but not their Gross Pay as that has not been calculated yet. 6. I select the Compute payroll. Payroll is computed for Tom & Sue.. 7. I select the Display payroll report. Tom & Sue’s information is displayed including their Gross Pay 8. I select Exit. Tom & Sue’s data is written to the file. 9. I run the program for the 2nd time. Tom & Sue’s data is read into list(s), the program displays its menu. 10. I select Input employee information. I enter Judy’s information (50 hours and 25.00/hour). 11. I select the Compute payroll. Payroll is computed for Tom, Sue, and Judy. 12. I select the Display payroll report. Tom, Sue, and Judy’s information is displayed including their Gross Pay 13. I select Exit. Tom, Sue, and Judy’s data is written to the file. THE PYTHON PROGRAM *** Projects with programs that have syntax errors automatically receive 0 points *** The program should do what is specified in the PROBLEM section above. The program should have the following features: 1) The first few lines of your program should be comments that state the program name, the author’s (your) name, date the program is released, and a brief description of the main task performed by the program. 2) Your program should have meaningful variable names. There should be a comment before each function definition and at each major function point: input, calculation, output. 3) Do not use nested functions. A nested function is a function inside another function. 4) Called functions should not call functions that called them. For example, you should not call main( ) from inputData( ). Also, functions should not call themselves. EXTERNAL DOCUMENTATION Type a report of your solution in a Word or OpenOffice Writer document. You should structure your document in four clear sections each with a subheading as follows: 1. PROBLEM DEFINITION The problem definition comes here. This is a summary of the PROBLEM section above. 2. DESIGN Give the algorithm in pseudocode form of the step by step statements to carry out the required programming task in English phrases. Pseudocode should be structured in such a way that statements inside functions are indented and statements inside loops and if … elif … else … statements are indented further. Explain the reasoning of the structure and logic of your program. You may use diagrams such as structure charts in addition to the pseudocode to present hierarchy and logic of your program. Pseudocode should not be in Python. 3. IMPLEMENTATION What was the platform and programming environment used? Name the Operating System and compiler. How did you test your program? Give the data used to test the program. Did you encounter any unusual situations when running the program (For example, what happens when an alphabetic character is input instead of an account number)? *** You should not put any Python code in the external documentation *** SUBMISSION METHOD a) Upload to Blackboard a copy of your external documentation. b) Upload to Blackboard a copy of your program (not MS Word or PDF formats but as generated by your editor saved with a .py extension). You will click on the black words “Programming project 5” in the “Programming projects” area on Blackboard and then click on “Browse My Computer” then attach your external documentation document, again click “Browse My Computer” and attach the program, then clicking SUBMIT. GRADING This program will be graded out of 100 points distributed as follows: ITEM MAX. POINTS External documentation 20 Style: comments, meaningful names, indentation 10 Program followed specification and compiles error free 30 Program works correctly 30 User Friendly interactions 10
Answered 2 days AfterApr 09, 2021

Answer To: CS115 INTRODUCTION TO COMPUTER PROGRAMMING Programming project #5 Functions, Files, and Lists...

Pratap answered on Apr 11 2021
136 Votes
PROGRAM DOCUMENTATION
PROBLEM DEFINITION:
Program starts with reading the employee data file if exists and displaying menu of input employees’ information, compute payroll for all employees, display payroll report and exit options. Based on the
operation selected by the user, the program will perform the tasks, which includes adding new employee details to the system, computing payrolls, display of payroll reports and while exiting the program will write the data from the system to a file.
ANALYSIS:
1. file – Variable to open employee data file.
2. data – Variable to store system data as multidimensional list.
3. choice – Variable to get user input as string. Input will be an option from the menu.
4. employee_name – Variable to get user input as string. Input will be name of the employee, whose details are to be added to the system data.
5. hours_worked – Variable to get user input as floating point integer. Input will be number of hours the employee worked.
6. pay_rate – Variable to get user input as floating point integer. Input will be the hourly pay rate of the employee.
7. choice – Variable to get user input as string. Input will be user’s decision to add more employee details to the system or not.
8. gross_pay – Variable to store computed data of gross payment for the employee as floating point integer.
DESIGN:
//The program will reads the employee data from the file
//provision for the user to add more employee details, compute and view payrolls & exit
Start Program Payroll Application
Set data to list
Function inputData
Pass in: nothing
Get global data
While True
    Begin
     Set employee_name to input
     Set hours_worked to input
     Set pay_rate to input
     Append [employee_name, hours_worked, pay_rate] to data
     Set choice to input
     If choice is ‘y’
        Continue loop
     Elif choice is ‘n’
        Break loop
     Else
        Print ‘invalid choice’
     End IF
    Exception
     Print ‘invalid input type’
End While
Pass out: nothing
End Function
Function computePay
Pass in: nothing
Get global data
For employee details in data
    If employee details has only 3 attributes
     If hours_worked is greater than 40
        Set gross_pay to (pay_rate * 1.5) * hours_worked
     Else
        Set gross_pay to pay_rate * hours_worked
     End If
    End If
End For
Pass out:...
SOLUTION.PDF

Answer To This Question Is Available To Download

Submit New Assignment

Copy and Paste Your Assignment Here