View the step-by-step solution to:

CS161: Assignment: Homework 5: Payroll System http://moodle.svcs.cs.pdx.edu/mod/assignment/view.php?

I started working on this payroll system but didn't feel I get the question asking. I am require to write payroll system in Python programing language. Please see attachment file for complete assignment requirement and code I started writing.
PSU CS 161 - Introduction to Programming and Problem Solving (Winter 2013) You are logged in as Nguyen Quan ( Logout ) Home My courses CS161 5 March - 11 March Homework 5: Payroll System Homework 5: Payroll System Due Wednesday, March 20 at 12:30AM(Tuesday Night) You are going to program a very simple payroll system. You can use any example code given during lectures (see the zip fles For the lectures on ±unctions and ±iles). Input File You will have a fle called "payroll.txt" in the same directory as your program fles. The Format oF the payroll fle is as Follows: <last name>,<frst name>,<rate>,<hours>,<gross pay> each employee is represented by a line with fve felds separated by commas. Here is an example fle: Nelson, ±rank, 10.0, 20.0, 200.0 Harrison, Johanna, 15.5, 40.0, 620.0 Mannon, Ethyl, 25.5, 35.5, 905.25 WARNING: Do not write your program to only work with this fle as our test script will NOT be using the exact same values as above, just the same Format. In Fact, it's guaranteed NOT to have 3 lines but it will be short (less than 200 lines). Your program should be able to take ANY number oF lines in the above Format (separated by commas) with any reasonable values (ie. the frst two felds will be string values and the last three felds will be ²oats). NOTE: When debugging your program, I would suggest you create your own test fles (Don't upload these test fles to Moodle; we only want your code fles). Menu Handling AFter your program loads this fle on start-up, then the Following menu is displayed: a - add a new employee d - delete an employee m - modify an employee p - print all employees You will then ask the user For a choice. You can use the skeletal program 'Full_Functions.py' From the ±unctions lecture (see ±eb 19 For the zip fle oF code For the Functions lecture) but you will need to modiFy it to work with the homework (ie. it shouldn't print anything about songs :-) ). Also, Feel Free to take out the code that asks iF the user wants to change their choice (it's more annoying than I thought). Choice Descriptions The choices do the Following: a - add an employee: Prompt the user For last name, frst name, rate and hours. Add employee to list oF employees. d - delete an employee: Prompt the user For an index into the list. Then delete employee at this index. m - modify an employee: Prompt the user For an index into the list and then prompt For a feld (“last name”, “frst name”,”rate”, “hours”). Then prompt For a new value. Replace the new value For the given feld For the employee at the given index. p - print all employees: All employee inFormation is printed to the screen in a nice Format (your choice oF what is meant by 'nice'). Also include the index into the list Navigation Home Site pages My profile My courses CS161 Participants General 8 January - 14 January 15 January - 21 January 22 January - 28 January 29 January - 4 February 5 February - 11 February 12 February - 18 February 19 February - 25 February 26 February - 4 March 5 March - 11 March Settings Course administration My profile settings My home Lecture Notes: Computing As A Profession Proficiency Demo Schedule Homework 5: Payroll System CS161: Assignment: Homework 5: Payroll System http://moodle.svcs.cs.pdx.edu/mod/assignment/view.php?id=390 1 of 2 3/7/13 6:29 PM
Background image of page 1
You are logged in as Nguyen Quan ( Logout ) CS161 for debugging purposes (ie. so you can see whether the right employee info got changed.) The program should update the grossPay Feld whenever an employee's pay rate and hours changes. This way when the print statement prints gross pay it will always be the correct value (also, it will be correct when the program writes to payroll.txt at the end). Ending the Program After the program is done with processing a choice, the user should be asked to continue. If yes, then the program should re-display the menu. If no, the program writes the payroll information back to "payroll.txt". This should be done by re-opening the “payroll.txt” Fle with a “w” mode which erases whats in the Fle already. The outputted format is the same as the inputted format so that when the program is re-run, the new “payroll.txt” can be read and parsed correctly. Requirements ±irst, your program needs to work correctly, In addition, to get full credit, your program needs the following: It needs to have one function called main() with no parameters. This function is the starting point to run your program. The program should call main() when run from shell. It should NOT call main if imported from another Fle. (see full_functions.py for how to do this). It needs to have at least 6 functions that you wrote (it will probably have much more than that). Note that you will need to load and save the Fle plus do four tasks so putting these into separate functions is a good idea. No function body or any global code should be more than 15 lines long. (NOT counting blank lines and comments). If the function starts getting longer, break it into two or more functions. Do NOT change global variables inside of functions (don't use the global statement). Pass variables into functions as parameters. The variable holding the employee information should NOT be global. Create it by reading it in inside main (the reading part can be done from another function and the list returned to main). Pass it to functions when it's needed and write the results out to Fle in main (or, again, pass it into another function as a parameter). You should have two Fles: One Fle to hold your main function called main.py. Another Fle to hold your functions and any global constants called functions.py. Zip these two Fles into one Fle (for Mac users, use whatever the equivalent of zip is) before uploading them to Moodle. You don't need to add your own payroll.txt Fle as we will use our own version of payroll.txt. You are free to use any combination of lists, dictionaries or classes to store the employee information as long as everything works correctly. You don't need to use classes for this assignment; you can do this assignment with a combination with lists and dictionaries. NOTE: If using classes, it is best to design one class to store ONE employee's info. Then create a list of objects of this class. In other words, don't store the list of employees inside the class itself. Available from: Thursday, 7 March 2013, 06:00 PM Due date: Wednesday, 20 March 2013, 12:30 AM Upload a file CS161: Assignment: Homework 5: Payroll System http://moodle.svcs.cs.pdx.edu/mod/assignment/view.php?id=390 2 of 2 3/7/13 6:29 PM
Background image of page 2
import sys yes_no_response = ["y","n"] menu_choices = ["a","d","m","p"] MAX_TRIES = 5 def printMenu(): print( """ Payroll System a - add a new employee d - delete an employee m - modify an employee p - print all employees """ ) def myOwnInput(message, valid_responses): ch = input(message) i = 0 while ch not in valid_responses: print("not a valid reponse. please choose: ",valid_reponses) ch = input(message_ i += 1 if (i > MAX_TRIES): print("I don't understand your choice. The program is quiting now. .. ") sys.exit(0) return ch def doMenu(): a = "y" ch = "" while(a == "y"): printMenu() ch = myOwnInput("Choose a menu item: ",menu_choices) print("you choose: " + ch) a = myOwnInput("Do you want to change your choice?",yes_no_reponse) return ch def main(): while True: ch = doMenu() a = myOwnInput("Do you want to continue?", yes_no_response) if (a == "n"): break print("end of program")
Background image of page 1
Sign up to view the entire interaction

Top Answer

Please see... View the full answer

functions.py

import sys
def printMenu():
print(
&quot;&quot;&quot;
Payroll System
admp&quot;&quot;&quot;
) add a new
delete an
modify an
print all employee
employee
employee
employees def myOwnInput(message,...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online