Employee Management System Python Phase 2 Please check Test cases before posting your answer. 1. Implement data persist
Posted: Mon Jun 06, 2022 4:34 pm
Employee Management System Python Phase
2
Please check Test cases before posting your
answer.
1. Implement data persistence:
a. The program should load the data from a specific file
(employee.dat) at startup and should save the data to the same file
before shutdown.
b. At startup, if the file does not exist, then the program
should initialize an empty dictionary in the memory and should not
create a data file. If the file does exist, then it's read into a
dictionary. The program should immediately close the file after
reading it into memory.
c. On exit, the dictionary, empty or not, should be written to
the data file. If the file already exists, the program should
overwrite it, thus saving the latest state of the dictionary. The
file should be immediately closed after writing into it.
d. For reading and writing a binary file, you should use pickle
module described in chapter 9.
e. Your program should have a function called load() that has
one string parameter containing filename and returns a dictionary
unpickled from that file. If the file does not exist, then it
should return an empty dictionary. The file should be closed before
returning from this function.
f. Your program should have a function called save() that has
two parameters, a dictionary and a filename. It should write the
dictionary into this file using pickle module and close the
file.
2. Implement find an employee by name (option 3)
3. Implement Display Statistics option (option 5)
a. Statistics will include the number of employees in each
department, as well as the total number of employees in the
company.
Hints for implementing statistics:
Create a temporary dictionary for keeping track of
departments.Scan all employees one by one.For each employee get the
department name.Check the temporary dictionary. If the department
is there, then update that entry by adding one to the value.If the
department is not there, then create a new entry where the key
equals the department name and value equals 1.At the end of the
process, when all employees are processed, you'll have a dictionary
with all departments and their employee counts.
Test Case 1
Welcome to Employee Management System (EMS)\n
Unable to load the database from binary file employee.dat.\n
Creating an empty database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 2
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee database is empty.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 3
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
111ENTER
Enter employee name:\n
Michael JordanENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Software EngineerENTER
Enter employee salary:\n
65000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
There is 1 employee in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
2ENTER
Enter an Employee ID or QUIT to stop:\n
111ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
112ENTER
Invalid selection.\n
Enter your selection (1..10):\n
QUITENTER
Invalid selection.\n
Enter your selection (1..10):\n
3ENTER
Enter an employee name or QUIT to stop:\n
Michael JordanENTER
Found 1 employee with that name.\n
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
Michael JacksonENTER
Invalid selection.\n
Enter your selection (1..10):\n
QUITENTER
Invalid selection.\n
Enter your selection (1..10):\n
5ENTER
Department Statistics:\n
\tDepartment: Engineering - 1 employee\n
There is 1 department in the database.\n
There is 1 employee in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 4
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1111ENTER
Enter employee name:\n
Michael JordanENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Software EngineerENTER
Enter employee salary:\n
65000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1112ENTER
Enter employee name:\n
Michael JacksonENTER
Enter employee department:\n
AccountingENTER
Enter employee title:\n
Accounting ManagerENTER
Enter employee salary:\n
55000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1113ENTER
Enter employee name:\n
Michael BrownENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Engineering ManagerENTER
Enter employee salary:\n
85000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1114ENTER
Enter employee name:\n
Michael WhiteENTER
Enter employee department:\n
AccountingENTER
Enter employee title:\n
Accounting ClerkENTER
Enter employee salary:\n
45000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Employee ID: 1111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Employee ID: 1112\n
\tName: Michael Jackson\n
\tDepartment: Accounting\n
\tTitle: Accounting Manager\n
\tSalary: 55,000.00\n
Employee ID: 1113\n
\tName: Michael Brown\n
\tDepartment: Engineering\n
\tTitle: Engineering Manager\n
\tSalary: 85,000.00\n
Employee ID: 1114\n
\tName: Michael White\n
\tDepartment: Accounting\n
\tTitle: Accounting Clerk\n
\tSalary: 45,000.00\n
There are 5 employees in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
5ENTER
Department Statistics:\n
\tDepartment: Engineering - 3 employees\n
\tDepartment: Accounting - 2 employees\n
There are 2 departments in the database.\n
There are 5 employees in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTERThank you for using Employee Management System (EMS)\n
2
Please check Test cases before posting your
answer.
1. Implement data persistence:
a. The program should load the data from a specific file
(employee.dat) at startup and should save the data to the same file
before shutdown.
b. At startup, if the file does not exist, then the program
should initialize an empty dictionary in the memory and should not
create a data file. If the file does exist, then it's read into a
dictionary. The program should immediately close the file after
reading it into memory.
c. On exit, the dictionary, empty or not, should be written to
the data file. If the file already exists, the program should
overwrite it, thus saving the latest state of the dictionary. The
file should be immediately closed after writing into it.
d. For reading and writing a binary file, you should use pickle
module described in chapter 9.
e. Your program should have a function called load() that has
one string parameter containing filename and returns a dictionary
unpickled from that file. If the file does not exist, then it
should return an empty dictionary. The file should be closed before
returning from this function.
f. Your program should have a function called save() that has
two parameters, a dictionary and a filename. It should write the
dictionary into this file using pickle module and close the
file.
2. Implement find an employee by name (option 3)
3. Implement Display Statistics option (option 5)
a. Statistics will include the number of employees in each
department, as well as the total number of employees in the
company.
Hints for implementing statistics:
Create a temporary dictionary for keeping track of
departments.Scan all employees one by one.For each employee get the
department name.Check the temporary dictionary. If the department
is there, then update that entry by adding one to the value.If the
department is not there, then create a new entry where the key
equals the department name and value equals 1.At the end of the
process, when all employees are processed, you'll have a dictionary
with all departments and their employee counts.
Test Case 1
Welcome to Employee Management System (EMS)\n
Unable to load the database from binary file employee.dat.\n
Creating an empty database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 2
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee database is empty.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 3
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
111ENTER
Enter employee name:\n
Michael JordanENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Software EngineerENTER
Enter employee salary:\n
65000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
There is 1 employee in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
2ENTER
Enter an Employee ID or QUIT to stop:\n
111ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
112ENTER
Invalid selection.\n
Enter your selection (1..10):\n
QUITENTER
Invalid selection.\n
Enter your selection (1..10):\n
3ENTER
Enter an employee name or QUIT to stop:\n
Michael JordanENTER
Found 1 employee with that name.\n
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
Michael JacksonENTER
Invalid selection.\n
Enter your selection (1..10):\n
QUITENTER
Invalid selection.\n
Enter your selection (1..10):\n
5ENTER
Department Statistics:\n
\tDepartment: Engineering - 1 employee\n
There is 1 department in the database.\n
There is 1 employee in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTER
Thank you for using Employee Management System (EMS)\n
Test Case 4
Welcome to Employee Management System (EMS)\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1111ENTER
Enter employee name:\n
Michael JordanENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Software EngineerENTER
Enter employee salary:\n
65000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1112ENTER
Enter employee name:\n
Michael JacksonENTER
Enter employee department:\n
AccountingENTER
Enter employee title:\n
Accounting ManagerENTER
Enter employee salary:\n
55000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1113ENTER
Enter employee name:\n
Michael BrownENTER
Enter employee department:\n
EngineeringENTER
Enter employee title:\n
Engineering ManagerENTER
Enter employee salary:\n
85000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
1ENTER
Enter an Employee ID or QUIT to stop:\n
1114ENTER
Enter employee name:\n
Michael WhiteENTER
Enter employee department:\n
AccountingENTER
Enter employee title:\n
Accounting ClerkENTER
Enter employee salary:\n
45000.00ENTER
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
6ENTER
Employee ID: 111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Employee ID: 1111\n
\tName: Michael Jordan\n
\tDepartment: Engineering\n
\tTitle: Software Engineer\n
\tSalary: 65,000.00\n
Employee ID: 1112\n
\tName: Michael Jackson\n
\tDepartment: Accounting\n
\tTitle: Accounting Manager\n
\tSalary: 55,000.00\n
Employee ID: 1113\n
\tName: Michael Brown\n
\tDepartment: Engineering\n
\tTitle: Engineering Manager\n
\tSalary: 85,000.00\n
Employee ID: 1114\n
\tName: Michael White\n
\tDepartment: Accounting\n
\tTitle: Accounting Clerk\n
\tSalary: 45,000.00\n
There are 5 employees in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
5ENTER
Department Statistics:\n
\tDepartment: Engineering - 3 employees\n
\tDepartment: Accounting - 2 employees\n
There are 2 departments in the database.\n
There are 5 employees in the database.\n
Main Menu:\n
1.\tAdd Employee\n
2.\tFind Employee by EID\n
3.\tFind Employee by Name\n
4.\tDelete Employee\n
5.\tDisplay Statistics\n
6.\tDisplay All Employees\n
7.\tBackup Database\n
8.\tRestore Database\n
9.\tPurge Database\n
10.\tExit\n
Enter your selection (1..10):\n
10ENTERThank you for using Employee Management System (EMS)\n