PPL - Assignment No 11
PPL - Assignment No 11
11
Problem statement: Create class EMPLOYEE for storing details (Name, Designation, gender,
Date of Joining and Salary). Define function members to compute a) total number of employees
in an organization b) count of male and female employee c) Employee with salary more than
10,000 d) Employee with designation “Asst. Manager”
Problem Description:
Program is to create a class named as Employee with some details as Name, Designation, Gender,
Date of Joining and Salary. Next program defines function members which compute total number
of employees in an organization, count of male and female employee, employee with salary more
than 10,000 and employee with designation “Asst. Manager”.
Theory Concept:
Class: A Class is like an object constructor, or a "blueprint" for creating objects. A class is a code
template for creating objects. Objects have member variables and have behavior associated with
them. In python a class is created by the keyword class.
Example: Create a class named MyClass, with a property named x:
class MyClass:
x=5
Object: An object is created using the constructor of the class. This object will then be called the
instance of the class.
Syntax: Instance =class(arguments)
Example: Create an object named p1, and print the value of x:
p1 = MyClass()
print(p1.x)
p1 = Person("John", 36)
p1.myfunc()
The self-parameter:
The self parameter is a reference to the current instance of the class, and is used to access variables
that belong to the class. It does not have to be named self, you can call it whatever you like, but it
has to be the first parameter of any function in the class:
Example: Use the words mysillyobject and abc instead of self:
class Person:
def __init__(mysillyobject, name, age):
mysillyobject.name = name
mysillyobject.age = age
def myfunc(abc):
print("Hello my name is " + abc.name)
p1 = Person("John", 36)
p1.myfunc()
Algorithm:
START
Step 1: Create a class Employee with attributes Name, Designation,
gender, Date of Joining and Salary
Step 2: Define variables and assign values
Step 3: Define __init__ () function and assign values to object properties.
Step 4: Define method functions with required conditions
Step 5: Define main () function
Step 6: Enter your choice
Step 7: Display / Print required results using print () function.
STOP
Flowchart:
Program with output :
class Employee:
totalEmployee = 0
males = 0
females = 0
def __init__(self,name,designation,gender,doj,salary):
self.name = name
self.designation = designation
self.gender = gender
self.doj = doj
self.salary = salary
Employee.totalEmployee += 1
if self.gender == ‘M’:
Employee.males += 1
else:
Employee.females += 1
@staticmethod
def totalEmployeeCount():
return Employee.totalEmployee
@staticmethod
def genderCount():
print(‘No. of Males:’,Employee.males)
print(‘No. of Females:’,Employee.females)
def isSalaryGreater10000(self):
if self.salary >’10000’:
return True
else:
return False
def isAsstManager(self):
if self.designation == “Asst Manager”:
return True
else:
return False
def create():
name = input(“Name:”)
designation = input(“Designation:”)
gender = input(“Gender(M/F):”)
doj = input(“Enter Date of Joining:”)
salary = input(“Salary:”)
emp = Employee(name,designation,gender,doj,salary)
return emp
def main():
emp_list = []
while(1):
print(“1.Create Employee\n2.Total Employees\n3.Gender count\n4.Employee with
salary >10000\n5.Asst Managers”)
choice = int(input(“Enter your choice: ”))
if choice == 1:
emp_list.append(create())
elif choice == 2:
print(“Total No. of Employees: “,Employee.totalEmployeeCount())
elif choice == 3:
print(Employee.genderCount())
elif choice == 4:
for emp in emp_list:
if emp.isSalaryGreater10000():
print(“Employee having salary than 10000: ”,emp.name)
elif choice == 5:
for emp in emp_list:
if emp.isAsstManager():
print(“Employee with designation as Asst Manager: ” ,emp.name)
else:
print(“Invalid choice”)
if __name__ == ’__main__ ’:
main()
OUTPUT:
1.Create Employee
2.Total Employees
3.Gender count
4.Employee with salary >10000
5.Asst Managers
Enter your choice: 1
Name: Sai
Designation: Manager
Gender(M/F): M
Enter Date of Joining: 02-02-2000 Salary: 40000