Create a class employee with protected members:Name,age,degree,genderCreate a member function to read the details. Create a derived class department by inheriting the employee class privately.Declare the protected members: department_name, designation.Create a member function to read the details of the department.Create a member function to display the details of employee class and department class.Create a derived class salary by inheriting the employee class privately with protected members: basic payCreate default constructor to read basic pay.Define a member function to calculate the gross pay. Gross_pay=basic_pay+DA+HRADA=30% of basic payHRA =12% of basic payCreate a member function to display the details of employee class and the grosspay.
Question
Create a class employee with protected members:Name,age,degree,genderCreate a member function to read the details. Create a derived class department by inheriting the employee class privately.Declare the protected members: department_name, designation.Create a member function to read the details of the department.Create a member function to display the details of employee class and department class.Create a derived class salary by inheriting the employee class privately with protected members: basic payCreate default constructor to read basic pay.Define a member function to calculate the gross pay. Gross_pay=basic_pay+DA+HRADA=30% of basic payHRA =12% of basic payCreate a member function to display the details of employee class and the grosspay.
Solution 1
Here is the Python code for the problem:
class Employee:
def __init__(self):
self._name = None
self._age = None
self._degree = None
self._gender = None
def read_details(self):
self._name = input("Enter name: ")
self._age = input("Enter age: ")
self._degree = input("Enter degree: ")
self._gender = input("Enter gender: ")
class Department(Employee):
def __init__(self):
super().__init__()
self._department_name = None
self._designation = None
def read_department_details(self):
super().read_details()
self._department_name = input("Enter department name: ")
self._designation = input("Enter designation: ")
def display_details(self):
print(f"Name: {self._name}, Age: {self._age}, Degree: {self._degree}, Gender: {self._gender}, Department: {self._department_name}, Designation: {self._designation}")
class Salary(Department):
def __init__(self):
super().__init__()
self._basic_pay = None
self._gross_pay = None
def read_basic_pay(self):
super().read_department_details()
self._basic_pay = float(input("Enter basic pay: "))
def calculate_gross_pay(self):
DA = self._basic_pay * 0.3
HRA = self._basic_pay * 0.12
self._gross_pay = self._basic_pay + DA + HRA
def display_salary_details(self):
super().display_details()
print(f"Basic Pay: {self._basic_pay}, Gross Pay: {self._gross_pay}")
# Test the classes
s = Salary()
s.read_basic_pay()
s.calculate_gross_pay()
s.display_salary_details()
This code first creates an Employee class with protected members and a function to read the details. Then it creates a Department class that inherits from Employee and adds its own members and functions. Finally, it creates a Salary class that inherits from Department, adds its own members and functions, and also overrides some of the functions from the parent classes.
Solution 2
Here is the Python code for the problem:
class Employee:
def __init__(self):
self._name = None
self._age = None
self._degree = None
self._gender = None
def read_details(self):
self._name = input("Enter name: ")
self._age = input("Enter age: ")
self._degree = input("Enter degree: ")
self._gender = input("Enter gender: ")
class Department(Employee):
def __init__(self):
Solution 3
Similar Questions
Create a class Employee with members name and ID and a default constructor to read the details of employeeCreate a derived class Salary from employee with members basic pay. Create a default constructor to read the basic pay.Create a derived class loan from salary with members DA,HRA,loan_amout, net_pay.Create a default constructor to read the loan_amount. Define a member function to calculate the netpay.Net_pay= (basic_pay+DA+HRA)-loan_amountDA=30% of basic payHRA =12% of basic pay
Create the class Employee with name, Empid, address, mailid, mobileno as data members.Inherit the classes Asstprofessor, Associateprofessor and Professor from employee class.Add Basic Pay (BP) as the member of all the inherited classes.Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Asstprofessor categories of employees.Calculate DA as 97% of BP, HRA as 7% of BP, PF as 13% of BP, Staff club fund as 0.1% of BP.Calculate gross salary and net salary.Generate payslip for Associateprofessor categories of employees, Create the objects for the inherited classes and invoke the necessary methods to display the Payslip.Calculate DA as 97% of BP, HRA as 4% of BP, PF as 13% of BP, Staff club fund as 0.2% of BP.Calculate gross salary and net salary.Generate payslip for Professor categories of employees,Choose the options PROGRAMMER 2.ASSISTANT PROFESSOR 3.ASSOCIATE PROFESSOR 4.PROFESSORinput
An employee will have a name, pay_rate, and list of hours_worked.Employee class must have following methods:Constructor – takes name and pay_rate. It will also creat an empty list of hours_worked.add_hours – takes hours as a parameter and add it to the hours_worked list.salary – calculates the salary for the employe (pay_rate x total hours worked).Write a main function that will:Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84
Define a class Employee. Display the personal salary details of three employeesusing single inheritance
Construct a class Person with attributes name, age, address and a methoddisplay() to display the details. Create a subclass Student with attributesrollno, mark1, mark2, and mark3. Override display() method and calculatethe grade. Create another subclass Faculty with attributes faculty_id,department, basic_pay and DA. Override display() method to calculate totalsalary as (basic_pay + DA) + 70% of (basic_pay + DA). Create instances ofStudent and Faculty and display the details
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.