1.

Define a class employee in Python with the given specifications:Instance variables:Employee number, name Methods:Getdata()- To input employee number and namePrintdata()- To display employee number and nameDefine another class payroll, which is derived from employeeInstance variable Methods:Inputdata() – To call Getdata() and input salary.Outdata() – To call Printdata() and to display salary.Define another class leave, which is derived from payroll.Instance variable No of days Methods:acceptdata() – To call Inputdata() and input no of days.showdata() – To call Outdata() and to display no of days.Implement the above program in python.

Answer»

class Employee(object):

# constructor to create an object

def_init_(self):

self.eno=0

self.name=“”

def Getdata(self):

self.eno=input(“Enter the Employee no:”)

self.name= raw_input(“Enter the Employee Name:”)

def Printdata(self):

print “Employee Number”,

self.eno print “Employee Name”,

self.name

class payroll(Employee):

def_init_(self):

super(payroll,self). _init_()

self.salary=0

def Inputdata(self): self.GetdataQ

self.salary=float(raw_input(“Enter the salary:”))

def Outdata(self): self.Printdata()

print “Salary is”,self.salary

class leave(payroll):

def_init_(self):

super(leave,self)._init_()

self.Noofdays=0 def acceptdata(self):

self.Inputdata()

self.Noofdays =input(“Enter leave days”)

def showdata(self): self.Outdata()

print “No. of leave days”,

self.Noofdays leaveobj = leave()

leaveobj. acceptdataO

leaveobj.showdata()



Discussion

No Comment Found