0% found this document useful (0 votes)
12 views5 pages

PPL - Assignment No 11

The document outlines the creation of an Employee class in Python to manage employee details such as Name, Designation, Gender, Date of Joining, and Salary. It includes methods to compute the total number of employees, count of male and female employees, identify employees with salaries greater than 10,000, and find employees with the designation 'Asst. Manager'. Additionally, it provides a flowchart, algorithm, and example code to demonstrate the implementation of the class and its functionalities.

Uploaded by

digiworksoft2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

PPL - Assignment No 11

The document outlines the creation of an Employee class in Python to manage employee details such as Name, Designation, Gender, Date of Joining, and Salary. It includes methods to compute the total number of employees, count of male and female employees, identify employees with salaries greater than 10,000, and find employees with the designation 'Asst. Manager'. Additionally, it provides a flowchart, algorithm, and example code to demonstrate the implementation of the class and its functionalities.

Uploaded by

digiworksoft2024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment No.

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)

The __init__() Function:


To understand the meaning of classes we have to understand the built-in__init__() function. All
classes have a function called __init__(), which is always executed when the class is being
initiated.
Use the __init__() function to assign values to object properties, or other operations that are
necessary to do when the object is being created:
Example: Create a class named Person, use the __init__() function to assign values for name
and age:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
print(p1.name)
print(p1.age)
Object Methods:
Objects can also contain methods. Methods in objects are functions that belong to the object.
Create a method in the Person class:
Example: Insert a function that prints a greeting, and execute it on the p1 object:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)

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

You might also like