Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

First, write a Python class called Student that has the following fields first_name: First name of the given student last_name: Last name of the given

First, write a Python class called Student that has the following fields

first_name: First name of the given student

last_name: Last name of the given student

student_id: Student ID of the given student

cgpa: Current Cumulative GPA of the given student.

Your Student class will define the following methods:

- __init__( self, first_name, last_name, student_id, cgpa )

Self-explanatory.

- __str__( self )

will return a string object that represents the data in the current Student object. The format of this string is left up to you, as long as it includes all four fields defined by the Student class.

Your task will be to keep track of multiple students loaded into memory and be able to answer certain questions mentioned below. To do this properly, you will create a second class called StudentManager, which will keep a dictionary of Student objects. The keys in this dictionary will be the student IDs that we will assume to be unique. First, you need to populate your "database" of students in your StudentManager, if you will.

Your StudentManager class will define the following instance methods--methods whose first parameter is "self":

- populate_from_file( self, filepath )

will populate the dictionary database in a StudentManager object by reading the student data in the provided file path. An input file for this purpose will have the following data format:

first_name_1, last_name_1, student_id_1, cgpa_1 first_name_2, last_name_2, student_id_1, cgpa_2 first_name_3, last_name_3, student_id_3, cgpa_3 . . . first_name_N, last_name_N, student_id_N, cgpa_N

That is, values for individual fields that correspond to what a Student object stores will be separated/delimtied with a comma character.

- filter( self, condition_function )

will return a dictionary of Student objects filtered in according to the condition implemented by the boolean function referenced by the condition_function parameter. For example, if one wishes to get all students whose lastnames start with "S," one would pass a function such as the following:

sm.filter( lambda student: student.last_name.startswith( "S" )

where sm is a StudentManager object that must have already been created.

- __str__( self )

will print out the contents of the internal database implemented using a dictionary. This function will traverse all Student objects in its dictionary and print each.

- average_cgpa( self )

will return the average CGPA of all Student objects in the StudentManager object.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions