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
Question
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
Solution
Sure, here is the Python code for the problem:
class Person:
def __init__(self, name, age, address):
self.name = name
self.age = age
self.address = address
def display(self):
print(f"Name: {self.name}, Age: {self.age}, Address: {self.address}")
class Student(Person):
def __init__(self, name, age, address, rollno, mark1, mark2, mark3):
super().__init__(name, age, address)
self.rollno = rollno
self.mark1 = mark1
self.mark2 = mark2
self.mark3 = mark3
def display(self):
super().display()
print(f"Roll No: {self.rollno}, Marks: {self.mark1, self.mark2, self.mark3}, Grade: {self.calculate_grade()}")
def calculate_grade(self):
average = (self.mark1 + self.mark2 + self.mark3) / 3
if average >= 90:
return 'A'
elif average >= 80:
return 'B'
elif average >= 70:
return 'C'
elif average >= 60:
return 'D'
else:
return 'F'
class Faculty(Person):
def __init__(self, name, age, address, faculty_id, department, basic_pay, DA):
super().__init__(name, age, address)
self.faculty_id = faculty_id
self.department = department
self.basic_pay = basic_pay
self.DA = DA
def display(self):
super().display()
print(f"Faculty ID: {self.faculty_id}, Department: {self.department}, Total Salary: {self.calculate_salary()}")
def calculate_salary(self):
return (self.basic_pay + self.DA) + 0.7 * (self.basic_pay + self.DA)
# Create instances of Student and Faculty
student = Student('John', 20, '123 Street', 1, 85, 90, 95)
faculty = Faculty('Smith', 45, '456 Avenue', 101, 'Computer Science', 50000, 10000)
# Display the details
student.display()
faculty.display()
This code first creates a base class Person with attributes name, age, and address and a method display() to display these details. Then it creates a subclass Student with additional attributes rollno, mark1, mark2, and mark3. The display() method is overridden in Student to display the student details and calculate the grade based on the marks. Another subclass Faculty is created with additional attributes faculty_id, department, basic_pay, and DA. The display() method is overridden in Faculty to display the faculty details and calculate the total salary. Finally, instances of Student and Faculty are created and their details are displayed.
Similar Questions
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.
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone_number, and e-mail address. A student has a status (freshman, sophomore, junior, or senior). An employee has an office, salary. A faculty member has office_hours and a rank. A staff member has a title. Override the toString() method in each of these classes to display their details. Write a Java application and subsequent pseudocode to implement/simulate the same.
Create a class called "Student" with private member variables for name, roll number, and marks in three subjects. Include public member functions to set the student details, calculate the average marks, and display the student detail
Create a class College and Faculty. Create at least 3 objects of each class and display all details using generic method display
Define a class Employee. Display the personal salary details of three employeesusing single inheritance
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.