Question

Create a program that presents a menu with these options: Add employee Print Employee Report Quit...

Create a program that presents a menu with these options:

  1. Add employee
  2. Print Employee Report
  3. Quit

Read the initial employee list from a text file and store the employee information into a DICTIONARY called empDict. Key empID, value is a LIST that contains name, payrate, and hours.

The text file will be structured as shown below, where each line contains the employee id, employee name, payrate and hours. Each entry on the line is separated by a comma and a space.

Example textfile:

111, George Gray, 10, 40
222, Amy Abrahmson, 10, 30
333, David Dell, 10, 42
444, Bob Brown, 5, 40

Example of the empDict after the information shown has been readd and stored:
{ 111: [“George Gray”, 10, 40], 222: [“Amy Abrahmson”, 10,30], 333: [“David Dell”, 10, 42], 444:[“Bob Brown”,5,40] }

The program must contain the following functions:

  • createMenu(optionList, menuTitle) à returns a string
  • getValidChoice(numOptions, menuStr) à returns an integer
  • addEmployee(empDict) à returns the updated dictionary.
             asks the user to enter id, name, payrate, and hours
            
             stores the information into the empDict
  • printReport(empDict) à doesn’t return anything. Simply prints a report
    calculates grossPay -- overtime hours (above 40) receive 1.5 times the regular payrate

Example of the report for the data shown:

                                         Employee Roster

ID            Name                                    PayRate               Hours                    GrossPay
=================================================================

111         George Gray $10.00                   40                           $400.00
222        Amy Abrahmson $10.00                  30                           $300.00
333        David Dell                            $10.00                   42                           $430.00
444         Bob Brown                          $ 5.00   40                           $200.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python Code:

def createMenu(optionList, menuTitle):
   """ Function that creates menu """
   # Initial string
   menuStr = ""
  
   # Creating menu string
   menuStr += " " + menuTitle + " "
  
   # Iterating over optionList
   for i in range(len(optionList)):
       menuStr += str(i+1) + " - " + optionList[i] + " "
      
   return menuStr
  
  
def getValidChoice(numOptions, menuStr):
   """ Function that reads input from user """
   # Printing menu
   print(menuStr)
   # Reading option
   opt = int(input(numOptions))
  
   return opt
  
  
def addEmployee(empDict):
   """ returns the updated dictionary. """
   # Reading employee information
   id = int(input(" Enter Employee ID: "))
   # Reading employee name
   name = input(" Enter Employee Name: ")
   # Reading employee Pay rate
   payrate = float(input(" Enter Employee Pay Rate: "))
   # Reading employee hours
   hrs = float(input(" Enter working hours: "))
  
   # Stores the information into the empDict
   empDict[id] = [name, payrate, hrs]
      
   return empDict
  
  
def printReport(empDict):
   """ prints a report """
   print(" Employee Roster ")
   print("%-5s %-25s %-15s %-15s %-15s"%("ID", "Name", "PayRate", "Hours", "GrossPay"))
   print("==============================================================================")
  
   # Iterating over dict
   for id in empDict.keys():
       print("%-5d %-25s $%-15.2f %-15d $%-15.2f"%(id, empDict[id][0], empDict[id][1], empDict[id][2], grossPay(empDict[id][1], empDict[id][2])))
  
def grossPay(payRate, hours):
   """ Calculating gross pay """
   if hours <= 40:
       return hours * payRate
   # OT Pay
   else:
       return ((40*payRate) + ((hours-40) * 1.5 * payRate))
  

def main():
   """ Main function """
   empDict = {}
   # Reading data from file
   with open("d:\Python\emp.txt") as fp:
       # Fetching line by line
       for line in fp:
           line = line.strip()
           # Splitting on comma
           fields = line.split(", ")
           # Adding an entry to dict
           empDict[int(fields[0])] = [fields[1], float(fields[2]), float(fields[3])]
  
   menuStr = createMenu(["Add employee", "Print Employee Report", "Quit"], "Employee Roster Menu")
   # Printing menu and processing
   while True:
       # Getting option
       option = getValidChoice("Enter your choice: ", menuStr)
      
       # Checking option
       if option == 1:
           addEmployee(empDict)
       elif option == 2:
           printReport(empDict)
       else:
           return
          
# Calling main function          
main()
      
        

__________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Create a program that presents a menu with these options: Add employee Print Employee Report Quit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in csis 152 style python programming language Read the initial employee information from a text file...

    in csis 152 style python programming language Read the initial employee information from a text file and store the employee information into a list of sublists called empRoster. Each sublist should contain [empID, name, payrate,hours] Here's an example of how empRoster will look: 111, "Sally Smith", 10, 401, 1222, "Bob Brown", 10, 42]1 The text file will be structured as shown below, where each line contains the employee id, employee name, payrate and hours. Each entry on the line is...

  • I am trying to modify this program so that it stores the employee's name in a...

    I am trying to modify this program so that it stores the employee's name in a c-string and can handle up to 100 employees (so it would mostly be a partially filled array), but I cannot get it to work. It works with two files that it is suppose to read input from. Then it prints output to an output file. Employee Info File (first file read, M/F should be ignored): 5    Christine Kim 30.00   2       1    F 15    Ray...

  • a database of employees that corresponds to the employee-payroll hierarchy is provided (see employees.sql to create...

    a database of employees that corresponds to the employee-payroll hierarchy is provided (see employees.sql to create the employees for a MySQL database). Write an application that allows the user to: Add employees to the employee table. Add payroll information to the appropriate table for each new employee. For example, for a salaried employee add the payroll information to the salariedEmployees table 1 is the entity-relationship diagram for the employees database Figure 1: Table relationships in the employees database [1]. Add...

  • C Program Assignment: 2-Add comments to your program to full document it by describing the most...

    C Program Assignment: 2-Add comments to your program to full document it by describing the most important processes. 3-Your variables names should be very friendly. This means that the names should have meaning related to what they are storing. Example: Instead of naming the variable that stores the hours worked for an employee in a variable called ‘x’ you should name it HoursWorked. 5-Submit your .c program (note that I only need your source code and not all files that...

  • Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee...

    Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee pay feature Company total pay feature The employee and company totals are stored in a text file for each individual company. 1. Create the following “input.txt” file. Each record consists of a first name, last name, employee ID, company name, hours worked, and pay rate per hour. Maria    Brown 10 Intel   42.75 39.0 Jeffrey Jackson 20 Boeing   38.0 32.5 Bernard Smith 30 Douglas   25.0...

  • Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency...

    Expand the payroll program to combine two sorting techniques (Selection and Exchange sorts) for better efficiency in sorting the employee’s net pay. //I need to use an EXSEL sort in order to combine the selection and Exchange sorts for my program. I currently have a selection sort in there. Please help me with replacing this with the EXSEL sort. //My input files: //My current code with the sel sort. Please help me replace this with an EXSEL sort. #include <fstream>...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT