In: Computer Science
Your local community college is opening a new campus in a different city and has asked your software firm to create a student roster program. You first have to develop a class that represents the roster of students who are currently studying in this local community college. What components and attributes will need to be included in the Student class? Why? Please include a Python code sample.
CODE:
#Creating a class Student with following components and
attributes.
class Student:
#Creating a constructor with studentID, firstName, lastName,
emailAddress, age and grades as attributes as they together
represent a particular student.
def
__init__(self,studentID,firstName,lastName,emailAddress,age,grades):
self.__studentID = studentID
self.__firstName = firstName
self.__lastName = lastName
self.__emailAddress = emailAddress
self.__age = age
self.__grades = grades
#A method to get the student id.
def get_student_id(self):
return self.__studentID
#A method to return the string representation of student.
def __str__(self):
return "Student Id: " + str(self.__studentID) + " First Name: " +
self.__firstName +" Last Name: "+self.__lastName+" Email: " +
self.__emailAddress+" Age: "+ str(self.__age)+" Grades:
"+self.__grades
#A student roster class which handles a group of student.
class StudentRoster:
#A static variable to hold the student group.
student_list = []
#A static method to add the students to particular group.
@staticmethod
def addStudent(student_obj):
StudentRoster.student_list.append(student_obj)
#A static method to remove a particular student based on it's
id.
@staticmethod
def removeStudent(student_id):
for student in StudentRoster.student_list:
if(student.get_student_id()==student_id):
StudentRoster.student_list.remove(student)
print("Student Removed")
return
print("Student not found")
#A static method to print details of all the students in the
group.
@staticmethod
def print_all():
for student in StudentRoster.student_list:
print(student)
#Creating object of student and studentRoster for different
operations and testing our classes.
obj = Student(1,'Aman', 'Soni','[email protected]',23,'A')
StudentRoster_obj = StudentRoster()
StudentRoster_obj.addStudent(obj)
StudentRoster_obj.print_all()
StudentRoster_obj.removeStudent(1)
CODE SCREENSHOT:
CODE OUTPUT: