Page 1 of 1

Write a Python code that satisfies the conditions explained below. You are free to use additional properties/methods: 1.

Posted: Wed Apr 27, 2022 3:51 pm
by answerhappygod
Write a Python code that satisfies the conditions explained
below. You are free to use additional properties/methods:
1. Define a parent class named Person. Each Person should have
several properties such as name, surname, year of birth, and
citizenship.
2. Define a child class named Student inherited from the Person
class. Student Class should be able to keep the following
information:
(i) If the Student is graduated/registered or dropout;
(ii) The CGPA of the student;
(iii) The list of the courses with their grades taken by the
Student;
(iv) The list of Courses that the Student registered in the
current semester
The Student class should have a method to calculate/update the
CGPA of the student.
3. Define an Employee class (based on the Person) to store
several properties, such as start date (to work) and salary. The
‘salary’ must be private. Therefore you should write a setter and a
getter method for the salary attribute. This class should also have
a method to calculate the "duration of service" by using the start
date.
4. Define an Instructor class based on the Employee
class to keep the following information about the instructor, such
as their title (Dr, Prof. Etc.); the last university graduated;
department; courses taught; courses taught in the current
semester.
Create 10 students by assigning them some courses.
Create 3 instructors by adding some information to each
property.
Write a code that asks the user to choose a student or an
instructor to get information:
############################### SAMPLE
grade_pts={'A':4.00,'A-':3.7,'B+':3.30,'B':3.00,'B-':2.70,
'C+':2.3,'C':2.0,'C-':1.7,'D+':1.3,'D':1.0,'F':0.0}
class Student:
def __init__(self,name):
self.name=name
self.courses=[]
self.cgpa=0.0
def add_a_course(self,course,grade):
self.courses.append([course,grade])
def calc_gpa(self):
total_credit=0.0
total_points=0.0
for crs in self.courses:
total_credit+=crs[0][1]
total_points+=crs[0][1]*grade_pts[crs[1]]
self.cgpa=total_points/total_credit
course1=["XX111",4]
course2=["XXY111",3]
course3=["ABC101",3]
course4=["XXX103",3]
student1=Student("Johny Deep") #for 2 students we
need to 10 students
student2=Student("John Seed")
student1.add_a_course(course1,'A-')
student1.add_a_course(course2,'B')
student1.calc_gpa()
student1.add_a_course(course3,'C')
student2.add_a_course(course1,'D')
student2.add_a_course(course3,'C-')
student2.add_a_course(course4,'B+')
student2.calc_gpa()
print(student1.name,student1.cgpa)
for n in student1.courses:
print("\t",n[0][0],n[1])
print(student2.name,student2.cgpa)
for n in student2.courses:
print("\t",n[0][0],n[1])