Programming Exercise #6 (Employee Management System): Use the Contact Manager Sy
ID: 3818950 • Letter: P
Question
Programming Exercise #6 (Employee Management System): Use the Contact Manager System from pages 456 to 462 as a guide. You will be using a dictionary, a menu system, and pickling to create your system. In most cases, you are simply changing the word “contacts” to “employees”.
a.Name your Python file employee_manager.py
b.The modules will be pretty much the same as in the Contact Manager System, except that you have four attributes in the Employee class, not three.
c.Test your program by adding the three Employee objects from page 479, then changing some attributes, deleting some employees, and adding your own. Close the program and start it again, to make sure your information is saved between sessions.
Explanation / Answer
//This is my Employee Class with four attributes: ID, number, dept and title
class Employee:
'ID, number, dept, jobTitle'
def __init__(self,ID,number,dept,jobTitle):
self.ID = ID
self.number = number
self.dept = dept
self.jobTitle = jobTitle
#Defining the setter and getter mothods:
def set_ID(self,ID):
self.ID = ID
def set_number(self,number):
self.number = number
def set_dept(self,dept):
self.dept = dept
def jobTitle(self,jobTitle):
self.jobTitle = jobTitle
def get_ID(self):
return self.ID
def get_number(self):
return self.number
def get_dept(self):
return self.dept
def get_jobTitle(self):
return self.jobTitle
def get_data(self):
print self.ID, self.number,self.dept,self.jobTitle
//Creating employee objects
import Employee
filename = 'contact_manager.dat'
my_file = open(filename,'rb')
unpickle_my_file = pickle.load(my_file)
def test_scenario():
user = input('Press 1 to Get Details of an employee, Press 2 to add employee'
' 3Press 3 to change an existing employee name, dept and job title'
' 4 Delete an employee from the dictionary'
' 5 Quit the program'
' Make your choice ')
if user == 2:
ID = raw_input('Enter the name ')
number = input('Enter the number')
deparment = raw_input('Enter the dept ')
jobTitle = raw_input('Enter the job title ')
entry = module from Employee??.class name(id,number,dept,jobTitle)??
empty_dictionary = {}
empty_dictionary[number] = entry
entry = Employee.Employee(id, number, dept, jobTitle)
if user==3
ID = raw_input('Enter the ID to whom you want to make changes ')
entry = module from Employee??.class name(id,??,??,??)??
number = input('Enter the New number')
deparment = raw_input('Enter the New dept ')
jobTitle = raw_input('Enter the New job title ')
empty_dictionary = {}
empty_dictionary[number] = entry
entry = Employee.Employee(id, number, dept, jobTitle)
if user==4
ID = raw_input('Enter the ID to whom you want to make changes ')
entry = module from Employee??.class name(id,??,??,??)??
empty_dictionary[number] = entry
print delete_Emp_Entry(empty_dictionary,ID);
my_file.close()
def delete_Emp_Entry(dict, key):
del dict[key]
return dict
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.