Question: A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: students CWID first_name : students first name

A) Please implement a Python script to define a student class with the following attributes (instance attributes):

  • cwid: students CWID
  • first_name : students first name
  • last_name: students last name
  • gender: students gender
  • gpa: students gpa

Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes.

Another thing you need to do is to define a constructor that takes a parameter of Python list. The constructor will use the list to initialize the instance attributes when a student object is instantiated. You can make any assumption on how values are stored in the list.

B)

Please define a class named student_list that is derived from Python list. Since student_list is derived from list, everything defined in list should be automatically inherited (into student_list). After you define student_list, please write a python script to build a student_list object using similar steps you followed for homework #1:

  1. The script instantiates a student_list object.
  2. The script gets the number of students via command line.
  3. The script gets the data for each student via command line.
  4. The script parses the data in step c into a list and instantiates a student object using the list.
  5. The script adds the student object created in step d to the student_list object (in step a).
  6. Use the print() function to print the student objects in student_list object. Please make sure that print() is able to output the content of each student object. You need to implement one of the magic method for student class.

Please make student and student_list classes as separate modules.

C) As we all know, Python implements an iterator for list so that the following statement works.

for e in s_list_obj:

print(e)

where s_list_obj is a student_list object and e is a student object.

You are asked to override the behavior of student_list class such that e in the above forloop becomes a Python dictionary where the attribute names and attribute values are the keys and values of the dictionary.

D)

Lets assume that you need to develop a generic function like below.

# this function takes two parameters def generic_sequence_func(p1, p2): for i in range(p2): for e in p1[i]:

print(e)

  • Please explain what kinds of exceptions might potentially be generated at run-time.
  • Please implement some logic to handle exceptions in this function. When an exception happens, the logic would print the following information:
    • Where the exception occurs
    • What are the class name and value of p1 and p2 when the exception occurs
  • Please also raise a custom exception with the above information.

E)

You are asked to implement a new method on the student_list class. The method is to find all student objects given a list of CWIDs (the input parameter of the new method). Please define and implement the method. In addition, please give a brief discussion on the complexity of the algorithm used in your implementation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!