Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

For this interactive assignment, you will apply all the concepts you learned in previous weeks and apply the use of sequential input and output operations to add two new functionalities to your...

1 answer below »
For this interactive assignment, you will apply all the concepts you learned in previous weeks and apply the use of sequential input and output operations to add two new functionalities to your Employee Management System.
· Export employees’ information to text file: This functionality will allow the user to save the employee information saved in the list to the file system. Each list entry should be saved into a new line. You may notice by now that closing the script will cost your Employee Management System to lose all entered employees’ information. Exporting the cu
ent system data into a file system will help you to save this information permanently on the hard disk and be able to use it at later time.
· Import employees’ information from text file: This functionality will help you to import preexisting employee information from a text file saved on the file system. Each line in the text should be saved as a new list entry. When you run your Employee Management System for the first time you should be able to populate the system with preexisting employee information, if there are any, instead of adding this information manually to the system. 
Once you have completed the functionalities, provide the following in your initial post:
· One screen shot of each completed functionality.
· An explanation of how you applied the use of sequential input and output operations to add the two new functionalities to the Employee Management System. paragraph format or bulletized
· A
ief description the purpose of this functionality. Paragraph format
· The script for each functionality.

Week 3 Assignment Employee Management System Functionality 4
The University of Arizona Global Campus
CPT200: Fundamentals of Programming Languages
Dr. Amjad
Employee Management System Functionality 4 Process
Employment of list data structure: List data structure is been employed within the dictionary for easier and flexible performance of the program to access and edit the values. The new functionalities demanded easier way of accessing the dictionary items. The lists are always better in terms of accessing when compared to strings. So “Search employee by SSN” and “Edit employee information” functionalities became easy to implement with lists in the play. With the proper dictionary key and proper index of the list item, the user will have the required item in hand. Hence the user can view o
and edit the items whenever required.
Variables: A dictionary of items with a key, list pairs is used to store the employee details. Dictionary key will be the integer of type string, which indicates the index of the employee in the system. The value for the key will be a list, which includes employee name, employee SSN, employee number, employee email and employee salary. The counter variable will be the length of the dictionary, which in turn tells the number of employees in the system.
Functions: Following are the function names and their functionalities –
· write_file(json_object) :- This is a generalized function used to write the dictionary of employee details(json_object) into a json file. The purpose of writing to a file is to save the added or edited data and read it when the program is restarted. This function is mentioned as generalized because writing is done during both adding and editing employee details. So this function is called twice in the program during adding and editing details.
· addEmp(i) :- This function will ask for employee details like name, SSN, number, email and salary. The parameter ‘I’ passed to the function should be the ‘count+1’, so that the new employee details will be added to the next index value. At the end after creating the appropriate dictionary object, this function will call ‘write_file(json_object)’ to write to the file, passing the employee dictionary created.
· generalView(key) :- This function is named as it is generalized function in displaying the employee details. This function is used whether the user wants to view all the employees, view employees based o index or view employees based on SSN. The parameter ‘key’ should be the key of the dictionary of which the items are to be displayed. Since lists are present in dictionary as values accessing them will be easier to display the required items in required format.
· viewAllEmployees() :- This function will collect all the keys present in the employee dictionary and passes it as parameters one by one while calling ‘generalView(key)’. Thus displaying all the employee details present in the system.
· viewEmpByIndex() :- This function will ask the user for employee SSN and calls ‘generalView(key)’ function with user entered SSN as the key parameter. Now the called function will display the employee details if the SSN matches with any of the keys, else it will throw e
or and the user has to try again.
· viewEmpBySSN(SSN) :- The parameter SSN is the SSN value entered by user. This function will search all the values(lists of employee details) in the employee dictionary and if it matches then the co
esponding ‘key’ parameter is sent while calling the ‘general_view(key)’ which will do the rest.
· editEmployeeDetails() :- This function will ask the user to enter SSN on which the employee details are to be edited. Before editing, the function will call ‘viewEmpBySSN(SSN)’ in order to display the existing details of the employee and then asks the user whether or not the user wants to edit the details. If user still wants to edit the details, user will be asked for new set of details for the employee and these details are written to the file using ‘write_file(json_object)’ function. And if the user doesn’t wants to edit, the program returns to main menu.
INPUT:
"""
-----EMPLOYEE MANAGEMENT SYSTEM-----
Follow the menu options to add, view, edit
employee details within the system
"""
#import li
aries
import re
import json
def write_file(json_object):
"""Write employee details to file"""
obj = json.dumps(json_object) #create a json object
with open('employee.json', 'w') as file:
XXXXXXXXXXfile.write(obj) #write to the file
file.close()
def addEmp(i):
"""Add new employee details"""
global json_object #use global data
print("----- Employee", i, "-----") #employee count
employeeName = input("Enter Name: ") #name of new employee
employeeSSN = input("Enter SSN: ") #employee SSN
employeeNumber = re.sub(r'(\d{3})(\d{3})(\d{4})',
XXXXXXXXXXr' XXXXXXXXXX', str(int(input("Enter phone number: ")))) #employee contact
employeeEmail = input("Enter email: ") #employee email
employeeSalary = '$' + str(float(input("Enter salary: "))) #employee salary
print('---------------------------------------------')
emp_dict = {i: [employeeName, employeeSSN, employeeNumber, employeeEmail, employeeSalary]}
json_object.update(emp_dict) #update the dictionary
write_file(json_object) #write to file
def generalView(key):
"""Generalized view of the dictionary
to call in different functions"""
global json_object
print("\t\t\t---------------------------- {} ----------------------------"
XXXXXXXXXXformat(json_object[key][0]))
print("SSN: ", json_object[key][1])
print("Phone: ", json_object[key][2])
print("Email: ", json_object[key][3])
print("Salary: ", json_object[key][4])
print("\t\t\t-----------------------------{}-----------------------------"
XXXXXXXXXXformat('-' * len(json_object[key][0])))
def viewAllEmployees():
"""View all employees"""
global json_object
for key in json_object.keys():
XXXXXXXXXXgeneralView(key) #for all keys in dictionary get the general view
def viewEmpByIndex():
"""Display employee only based on index value"""
global json_object
userInput = int(input("Please enter index value to view employee's information: "))
generalView(str(userInput)) #get general view only for the index
def viewEmpBySSN(SSN):
"""Display employee only based on SSN"""
global json_object
for key in json_object.keys():
XXXXXXXXXXif SSN in json_object[key]:
XXXXXXXXXXgeneralView(key) #get the general view if SSN is present in the dictionary item

eak #once the item is found
eak the loop
XXXXXXXXXXelse:
XXXXXXXXXXcontinue #continue the loop if not found
else:
XXXXXXXXXXprint("No match found for the entered SSN!") #match not found in dictionary
def editEmployeeDetails():
"""Function to edit employee details"""
global json_object
userInput = input("Please enter employee SSN to fetch details: ") #user input SSN
viewEmpBySSN(userInput) #fetch employee details using viewEmpSSN function
userQuery = input("Do you wish to edit employee details('Y' for Yes or 'N' for No)? ")
if userQuery == "N":
XXXXXXXXXXprint("Return to menu.")
elif userQuery == "Y":
XXXXXXXXXXfor key in json_object.keys():
XXXXXXXXXXif userInput in json_object[key]: #find the matching SSN in the dictionary items
XXXXXXXXXXprint("----- Employee", {}, "-----".format(key))
XXXXXXXXXXjson_object[key][0] = input("Enter employee name: ") #edit name
XXXXXXXXXXjson_object[key][1] = input("Enter employee SSN: ") #edit SSN
XXXXXXXXXXjson_object[key][2] = re.sub(r'(\d{3})(\d{3})(\d{4})', r' XXXXXXXXXX',
XXXXXXXXXXstr(int(input("Enter employee phone number: ")))) #edit numbe
XXXXXXXXXXjson_object[key][3] = input("Enter employee email: ") #edit email
XXXXXXXXXXjson_object[key][4] = '$' + str(float(input("Enter salary: "))) #edit salary
XXXXXXXXXXprint('---------------------------------------------')
XXXXXXXXXXwrite_file(json_object) #write the updates to file
else:
XXXXXXXXXXprint("Invalid option") #invalid SSN entry
while True:
try:
Answered 4 days After Mar 24, 2021

Solution

Shashi Kant answered on Mar 27 2021
155 Votes
Emp/Emp.py
#import li
aries
import re
import json
def write_file(json_object):
"""Write employee details to file"""
obj = json.dumps(json_object) #create a json object
with open('employee.json', 'w') as file:
file.write(obj) #write to the file
file.close()
def addEmp(i):
"""Add new employee details"""
global json_object #use global data
print("----- Employee", i, "-----") #employee count
employeeName = input("Enter Name: ") #name of new employee
employeeSSN = input("Enter SSN: ") #employee SSN
employeeNumber = re.sub(r'(\d{3})(\d{3})(\d{4})',
r'(\1)\2-\3', str(int(input("Enter phone number: ")))) #employee contact
employeeEmail = input("Enter email: ") #employee email
employeeSalary = '$' + str(float(input("Enter salary: "))) #employee salary
print('---------------------------------------------')
emp_dict = {i: [employeeName, employeeSSN, employeeNumber, employeeEmail, employeeSalary]}
json_object.update(emp_dict) #update the dictionary
write_file(json_object) #write to file
def generalView(key):
"""Generalized view of the dictionary
to call in different functions"""
global json_object
print("\t\t\t---------------------------- {} ----------------------------"
.format(json_object[key][0]))
print("SSN: ", json_object[key][1])
print("Phone: ", json_object[key][2])
print("Email: ", json_object[key][3])
print("Salary: ", json_object[key][4])
print("\t\t\t-----------------------------{}-----------------------------"
.format('-' * len(json_object[key][0])))
def viewAllEmployees():
"""View all employees"""
global json_object
for key in json_object.keys():
generalView(key) #for all keys in dictionary get the general view
def viewEmpByIndex():
"""Display employee only based on index value"""
global json_object
userInput = int(input("Please enter index value to view employee's information: "))
generalView(str(userInput)) #get general view only for the index
def viewEmpBySSN(SSN):
"""Display employee only based on SSN"""
global json_object
for key in json_object.keys():
if SSN in json_object[key]:
generalView(key) #get the general view if SSN is present in the dictionary item

eak #once the item is found
eak the loop
else:
continue #continue the loop if not found
else:
print("No match found for the entered SSN!") #match not found in dictionary
def editEmployeeDetails():
"""Function to edit employee details"""
global json_object
userInput = input("Please enter employee SSN to fetch details: ") #user input SSN
viewEmpBySSN(userInput) #fetch employee details using viewEmpSSN function
userQuery = input("Do you wish to edit employee details('Y' for Yes or 'N' for No)? ")
if userQuery == "N":
print("Return to menu.")
elif userQuery == "Y":
for key in json_object.keys():
if userInput in json_object[key]: #find the matching SSN in the dictionary items
print("----- Employee", {}, "-----".format(key))
json_object[key][0] = input("Enter employee name: ") #edit name
json_object[key][1] = input("Enter employee SSN: ") #edit SSN
json_object[key][2] = re.sub(r'(\d{3})(\d{3})(\d{4})', r'(\1)\2-\3',
str(int(input("Enter employee phone number: ")))) #edit numbe
json_object[key][3] = input("Enter employee email: ") #edit email
json_object[key][4] = '$' + str(float(input("Enter salary: "))) #edit salary
print('---------------------------------------------')
write_file(json_object) #write the updates to file
else:
print("Invalid option") #invalid SSN entry
while True:
try:
"""read employee.json if exist"""
file = open(r'employee.json', 'r')
json_object = json.load(file)
file.close()
except:
json_object = dict() #create...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here