Python Practice › OOP Programs › Program 18
Employee management system
Write a small employee management system with add, raise and report features.
Output
101 Asha 55000 102 Ravi 62000
Approach
- Store employees in a dictionary keyed by id.
Solution
class Employee: def __init__(self, emp_id, name, salary): self.emp_id, self.name, self.salary = emp_id, name, salary class Company: def __init__(self): self.staff = {} def hire(self, emp): self.staff[emp.emp_id] = emp def give_raise(self, emp_id, percent): emp = self.staff[emp_id] emp.salary = round(emp.salary * (1 + percent / 100)) def report(self): for e in self.staff.values(): print(f"{e.emp_id} {e.name:<6} {e.salary}") c = Company()c.hire(Employee(101, "Asha", 50000))c.hire(Employee(102, "Ravi", 62000))c.give_raise(101, 10)c.report()Output
101 Asha 55000 102 Ravi 62000
Learn the concept
New to this topic? Read the lesson, then come back.