question archive For this assignment, continue to use variables, functions, and control structures to improve the "View all Employees" functionality developed in Week 3 and utilize functions and the passing of parameters to add two new functionalities to the Employee Management System

For this assignment, continue to use variables, functions, and control structures to improve the "View all Employees" functionality developed in Week 3 and utilize functions and the passing of parameters to add two new functionalities to the Employee Management System

Subject:Computer SciencePrice:6.89 Bought3

For this assignment, continue to use variables, functions, and control structures to improve the "View all Employees" functionality developed in Week 3 and utilize functions and the passing of parameters to add two new functionalities to the Employee Management System.

 

Update the "View all Employees" functionality developed in Week 3 to view the result in the following format:

 

---------------------------- Mike Smith -----------------------------

 

SSN: 123123123

 

Phone: 111-222-3333

 

Email:

 

Salary: $6000

 

------------------------------------------------------------------------

 

---------------------------- Sara Smith -----------------------------

 

SSN: 123123111

 

Phone: 111-222-4444

 

Email:

 

Salary: $6500

 

------------------------------------------------------------------------ 

 

Now continue to employ the list data structure and utilize functions to add the following two new functions:

 

  • Search employee by SSN: This functionality makes use of looping and string parsing to search all the employees in the list and returns the information of the employee who has a SSN similar to the one that the user provided. The system should display the employee information in the following format:

 

---------------------------- Mike Smith -----------------------------

 

SSN: 123123123

 

Phone: 111-222-3333

 

Email:

 

Salary: $6000

 

------------------------------------------------------------------------

 

  • Edit employee information: This functionality makes use of the "Search employee by SSN" function first to find the right employee, then it will allow the user to edit the information of the selected user.

 

Once completed Functionality 4, provide the following in a Word document.

 

  • One screen shot of each completed functionality.
  • An explanation of how variables, functions, and control structures were used to improve the "View all Employees" functionality to view results in the format provided.
  • An explanation of how you employed the list data structure to add the two new functions, "Search employee by SSN" and "Edit employee information."
  • A brief description of the purpose of this functionality.
  • The script for this functionality.

 

My Functionality 3 was:

# function to add employee (functionality 1)

def addEmployee():

 employeeName = input("nEnter Employee Name: ")

 employeePhone = input("Enter Employee Phone Number: ")

 employeeSSN = input("Enter Employee SSN: ")

 employeeEmail = input("Enter Employee Email: ")

 employeeSalary = input("Enter Employee Salary: ")

 employeeInfo = []

 employeeInfo.append(employeeName)

 employeeInfo.append(employeePhone)

 employeeInfo.append(employeeSSN)

 employeeInfo.append(employeeEmail)

 employeeInfo.append(employeeSalary)

 return employeeInfo

# function to view all employees (functionality 2)

def viewAllEmployee(employees):

 if len(employees) == 0:

  print("nThere is no employeesn")

 else:

  print("n")

  for employee in employees:

   print("nEmployee "+str(employees.index(employee)+1)+" details:")

   print("tEmployee_Name:",employee[0])

   print("tPhone:",employee[1])

   print("tSSN:",employee[2])

   print("tEmail:",employee[3])

   print("tSalary:",employee[4])

   print("n")

# Main (functionality 3)

employees = []

employeeCount = 0

while True:

 print("1. Add Employeen2. View all Employeesn3. Exit")

 choice = int(input("nEnter a choice (1/2/3): "))

 if choice == 1:

  info = addEmployee()

  employees.append(info)

  employeeCount += 1

  print("n"+str(employeeCount)+" employee's information is addedn")  

 elif choice == 2:

  viewAllEmployee(employees)

 elif choice == 3:

  break

 else:

  print("nInvalid choice. Please Try again...n")

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

def addEmployee():
   employeeName = input("\nEnter Employee Name: ")
   employeePhone = input("Enter Employee Phone Number: ")
   employeeSSN = input("Enter Employee SSN: ")
   employeeEmail = input("Enter Employee Email: ")
   employeeSalary = input("Enter Employee Salary: ")
   employeeInfo = []
   employeeInfo.append(employeeName)
   employeeInfo.append(employeePhone)
   employeeInfo.append(employeeSSN)
   employeeInfo.append(employeeEmail)
   employeeInfo.append(employeeSalary)
   return employeeInfo
# function to view all employees (functionality 2)
def viewAllEmployee(employees):
   if len(employees) == 0:
      print("\nThere is no employees\n")
   else:
      print("\n")
   for employee in employees:
      print("\nEmployee "+str(employees.index(employee)+1)+" details:")
      print("\tEmployee_Name:",employee[0])
      print("\tPhone:",employee[1])
      print("\tSSN:",employee[2])
      print("\tEmail:",employee[3])
      print("\tSalary:",employee[4])
      print("\n")


def search_by_ssn(employees, ssn):
   for index, employee in enumerate(employees):
      if(employee[2] == ssn):
         return index
   return None


def update_employee(employees, index):
   employees[index][0] = input("\nEnter Employee Name: ")
   employees[index][1] = input("Enter Employee Phone Number: ")
   employees[index][2] = input("Enter Employee SSN: ")
   employees[index][3] = input("Enter Employee Email: ")
   employees[index][4] = input("Enter Employee Salary: ")
# Main (functionality 3)
employees = []
employeeCount = 0
while True:
   print("1. Add Employee\n2. View all Employees\n3. Search By SSN\n4. Update employee info\n5. Exit")
   choice = int(input("\nEnter a choice (1/2/3): "))
   if choice == 1:
      info = addEmployee()
      employees.append(info)
      employeeCount += 1
      print("\n"+str(employeeCount)+" employee's information is added\n")  
   elif choice == 2:
      viewAllEmployee(employees)
   elif choice == 3:
      employeeSSN = input("Enter Employee SSN: ")
      index = search_by_ssn(employees, employeeSSN)
      if(index is None):
         print("Employee not found.")
      else:
         viewAllEmployee([employees[index]])
   elif choice == 4:
      employeeSSN = input("Enter Employee SSN: ")
      index = search_by_ssn(employees, employeeSSN)
      update_employee(employees, index)
      print("Employee updated")
   elif choice == 5:
      break
   else:
      print("\nInvalid choice. Please Try again...\n")

 

I created two additional functions:

search_by_ssn: this function tries to find the employee by ssn, if nothing is found, it returns None, otherwise, it returns the index in the employees list. The function enumerate returns the index and the employee for each position of employees list.

update_employee: This function receives the index of employees list to be updated, and asks the user for the new information.

 

The functionality of searching by ssn uses viewAllEmployee to print the info. I'm passing a list that has only the employee to be printed. I did this way to avoid repeating code.

Related Questions